-
Notifications
You must be signed in to change notification settings - Fork 267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
when i use .setState(..) dropdown is not showing any item #79
Comments
The component maintains its own selection state. You don't need to do that. |
@mrchief but i need to selectedNodes data. so how else can get the data of the items I have checked ? |
Re-renders, when the data has not changed (for sub components), is a terrible waste of cycles. So one suggestion would be to see if you can avoid that, which in turn will avoid this issue in the first place. If, for some reason, you can't do that, then you can use the approach laid out here: Prevent re-render on parent to prevent the tree control from getting re-initialized every time. Hope this helps. If you have more questions, it'd be helpful if you can create a CodeSandbox (you can fork any of the existing ones and make your changes on top) that highlights the issues. |
I also call setState, idk thought that was the react way :). They way I solved it: Create initial tree, with paths to each node. When toggled, find the node that was toggled and set it as toggled/not-toggled (if it becomes closed => close its children etc). When checking/unchecking traverse tree and update etc. I also keep track of the path to each node so that I know If I can ignore part of the tree. This is maybe overkill, but feels like you have better controll with the setState solution. Some of this specific to my domain, like filterString and stuff. The component is used to select affected switches for an ISP blackout (idk what its called in english) . Maybe all of this is overkill. Maybe the better solution is to just set a variable with the selectedNodes and don't call setState.. Hmm insert code did not work => https://pastebin.com/piAJRSV0 |
ahhh. i understand now. of course you right. thanks for example. I think I should improve myself on HOC |
Yes, its perfectly valid to hold data in a variable if it doesn't affect the UI.
I use it the same way (i.e. create paths and then just use that to manipulate/send data to backend). Re-initializing something like a tree is not cheap, and so should be avoided. You also loose any previous search memoizations when you re-initialize the tree. @josvegit Maybe avoiding re-render will help with your 15k nodes as well. |
Yeah felt a bit like I was doing something that was already solved. Ill see if It makes a big difference, and maybe I can get you some scrambled version of the data I use to populate the component. |
Wow made the component feel much more responsive ! Search is still slow, ill get you the data somehow :) |
FWIW, you can maybe use one of these tools to generate data that's similar (in terms of complexity) https://www.json-generator.com/ |
Just created #80 to track search improvements. Can this be closed now? |
I want to set the selectedNodes data from the onChange to the state.
but when i use .setState(..) transferred to state but dropdown is not showing any item.
doesn't selected any items and doesn't show any selected items.
The text was updated successfully, but these errors were encountered: