gregnb / gregnb/mui-datatables

updateValue in customBodyRender doesn't work when used with useState

Open
#1,271 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2.7k
Forks
906
PR merge metrics
No merged PRs in 30d

Description

`updateValue` in `customBodyRender` doesn't update value when setting values via `useState`.

## Expected Behavior
`updateValue` updates the row properly when used with `useState`

## Current Behavior
`updateValue` doesn't update `value` and the row is not changed in `customBodyRender`

## Steps to Reproduce (for bugs)

Below is an example to highlight the problem. I did not put entire code as they are just distractions for now.

```
customBodyRender: (value, tableMeta, updateValue) => {
const handleSearch = () => {
const monthlySearches = tableMeta.rowData[1];
setIsEvaluating(true);
setClickedRowIndex(tableMeta.rowIndex);
updateValue(true);
setTest('hello');
ApiClient.get(`/test`, { params: { historicalVolume: monthlySearches } })
.then(res => {
updateValue(res.history);
setSearches(searches);
})
.catch(err => {
updateValue(null)
if (err.status === 422) {
setErrorMsg(`${err.data}`);
setAlertSeverity('error');
setOpenErrorMsg(true);
}
})
.finally(() => {
setIsEvaluating(false);
});
};

return (



{ Number.isInteger(value) ?



:



}
{ tableMeta.rowIndex === clickedRowIndex && isEvaluating && }



)
}
```

Is it possible to mix both and still use `updateValue` under `customBodyRender`?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.