[DataTable] Infinite loop in DataTable property onSelectionChanged
Hi,
I have following problem: When I setState inside function I pass to onSelectionChanged, the function onSelectionChanged starts to call itself infinitely as loop.
rowSelectionChanged(data){
this.setState({"rowsSelected": data});
}
onSelectionChanged={this.rowSelectionChanged.bind(this)}
Link to code pen to see the test: http://codepen.io/xdvarpunen/pen/LkykVK?editors=1011
Quote from Discord react-mdl room:
@asdf Sorry for the delay, I tested your codepen (thanks for that) and I also noticed the infinite loop. This is caused by this line :/ https://github.com/tleunen/react-mdl/blob/master/src/DataTable/Selectable.js#L61 I first did this because if the table receives new data, the selected rows might change as well, so I wanted to notify the "parent". But yep it's not the best idea actually 😒 Would you mind creating a ticket issue for this specific bug please? GitHub tleunen/react-mdl react-mdl - React Components for Material Design Lite
Maybe the solution would just be to check if the selected rows has changed before calling the callback
-XDVarpunen
I'll try to make a bit more fixes and changes before releasing a new version early next week. Please be patient :)
Thank you very much! Tyt (:
New problem:
On first click the selection shows empty, On second click the selection shows correctly selected rows.
If click the select all box, it shows reverse choice: On first click it shows empty, On second click it shows all selected.
You shared with me this codepen: http://codepen.io/xdvarpunen/pen/LkykVK?editors=1011
So you're trying to log the state right after setting it. This is the issue. setState is a synchronous operation, so sometimes you might not have the right info if you log just after setting it.
setState() does not immediately mutate this.state but creates a pending state transition. Accessing this.state after calling this method can potentially return the existing value. From: https://facebook.github.io/react/docs/component-api.html
Are were certain that the issue is no longer exists? Been upgraded from 1.7.1 to 1.11.0. And the problem seems to come back. Working fine on 1.7.1 previously.
And now we are seeing it again.
Got this “Uncaught Invariant Violation: Maximum update depth exceeded” During Multiple Selection
More details: https://stackoverflow.com/questions/60608241/got-this-uncaught-invariant-violation-maximum-update-depth-exceeded-during-mu