mui-datatables icon indicating copy to clipboard operation
mui-datatables copied to clipboard

Error at onTableChange passing to state

Open mhmmdakbr opened this issue 7 years ago • 2 comments

So i want to set the tableState to my state, and then it shows me an error = erorr1

if you want to try this is my codesandbox https://codesandbox.io/s/zealous-water-brusy?fontsize=14

Tech Version
Material-UI
MUI-datatables
React
browser
etc

mhmmdakbr avatar Jun 28 '19 08:06 mhmmdakbr

This is due to the way that react works. You are changing state inside the render function in such a way that it is causing a re-render, which then fires the state change again, and so on...

To fix this, you have to pull your data out of the render function and check the previous state against the new state when you update to make sure you are only updating when there is a change.

Your issue is similar to the one here, about the common mistake of updating state in componentDidUpdate without first checking that the state has changed: https://reactjs.org/docs/react-component.html#componentdidupdate.

gabrielliwerant avatar Jun 29 '19 07:06 gabrielliwerant

can you help me to fix this in my codesandbox ? cause i'm very stuck

mhmmdakbr avatar Jun 29 '19 11:06 mhmmdakbr