-
Notifications
You must be signed in to change notification settings - Fork 45.9k
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
Slow state update with long list of data #26215
Comments
I think the problem is just the large complexity of your algorithms and the cost of unnecessary recalculations. |
@sohaibMan I was able to eliminate it by refactoring
But, I'm still curious
|
For my app this feature work great |
When we update one record of the entire array, react has to render all components for the table. useState happens fast. Painting the DOM is the one that is being delayed. To test that, one can try clicking on other checkboxes, and the dom will be unresponsive. From my experience, when such a huge list is involved, i would manage the states for each table row rather than having a global state at the top level. So in this case, toggling a check box will only re-render a particular table row and not the entire table. Combining that with virtual lists we can achieve snappy UI even for huge lists. |
@hhkk28 Then why it works fast when I use |
@alexander-vashchuk React re-renders only when a state or props is changed. In case of updating refs, react re-render any nodes. That is the intended behavior. In react developer tools, enable the toggle Please check this well written blog on react rendering behaviour to understand when react triggers re renders and when it does not - Why React Re-Renders |
You can use this tool to help you figure out why some components are rerendering and how to resolve them on your side to avoid unnecessary rerenders. |
I think the state comparision for the long list also takes long time. |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you! |
React version: 18.2.0
Steps To Reproduce
Live example:
CodeSandbox
The current behavior
Checkbox works very slow
The expected behavior
Checkbox works instantly
The text was updated successfully, but these errors were encountered: