'React Material Table : onRowAdd not refreshing
I am using Material Table for displaying table data.
Using onRowAdd, I am able to add a new row but the page is not refershing. It reloads and get stuck then I have to reload it again.
newData =>
new Promise(resolve => {
setTimeout(() => {
resolve();
this.setState(prevState => {
this.props.saveSetting(newData, this.state.resource, "generalmessage.successMessage");
const data = [...prevState.data];
return { ...prevState, data };
});
}, 600);
})
Save Setting is the function that I am calling in sagas.
I am not able to understand what I am doing wrong here. Please guide me in this.
Solution 1:[1]
I'm not sure if you're using useState
in your component.
Anyway, I did my onRowAdd
this way and it's working:
onRowAdd: (newRow) =>
new Promise((resolve, reject) => {
setTableData([...tableData, newRow]);
setTimeout(() => resolve(), 500);
})
Hope this helps
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Luv_Python |