State management within OnChange #452
Replies: 2 comments 7 replies
-
This is the classic React rendering mistake which hooks, by virtue their simplicity makes all too more obfuscated to spot. Anytime you do a You can use prevent-re-render-on-parent-render-hoc approach (there's a hook based example somewhere in old issues) or refactor your app where you do not setState within |
Beta Was this translation helpful? Give feedback.
-
@mrchief I read in a discussion where the dropdown tree select component will itself manages its state, so the onChange need not be explicitly called? if i dont call the onchange, selecting/unselecting works perfectly fine if so i need to update the selected/unselected node to the parent component, if i do that in onChange method, it throws error during removing the selected value "Cannot read property checked of undefined" |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Greetings,
I've created a very basic example of the ReactTreeDropDown component being wrapped in a HOC that attempt to handle an internal state of the selectedNodes,
I have attempted to use the OnChange handler to capture the selected nodes, but when I attempt to modify the state, the ReactTreeDropDown component fails to render properly.
It appears that the setState call is superseding the internal state management and forcing the component to re-render before it can actually set its internal state/render
here's an example
https://codesandbox.io/s/react-dropdown-tree-select-forked-6n9e8
Selecting a top level item appears to work, but expanding the tree and selecting any sub item fails to correctly select the item.
Is there a recommended way to capture the selected nodes?
Beta Was this translation helpful? Give feedback.
All reactions