How to batch multiple store updates? #2275
Unanswered
raviteja83
asked this question in
Q&A
Replies: 2 comments 2 replies
-
|
For frequent updates, we shouldn't trigger React for each update. One technique is known as transient update. Lines 247 to 262 in 517524d There might be another way, but we shouldn't use If anyone has similar experience, don't hesitate to share ideas. |
Beta Was this translation helpful? Give feedback.
2 replies
-
|
I would put those updates in a queue, save them in an object, within 60/120 seconds an agent would be responsible to check that object and set the data to the you’re using currently — that’s important so your whole UI don’t keep being updated.
Best regards,
Gabriel Oliveira
+55 48 99107 5872
…On Dec 28, 2023 at 10:07 -0300, Daishi Kato ***@***.***>, wrote:
another idea would be batching updates outside of Zustand.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a websocket where I receive messages and store them in a zustand store. Sometimes, I would receive more than 40msg/sec or so. For each message I am converting the object to a particular format and storing in zustand store. In this case, 40 setState have happened. Each updating the same fields(adding to the existing list). Also, I am rendering the above messages in a virtualised list
How do I improve the handling of this and reduce the number of setState calls? After sometime, the UI is frozen and CPU usage goes to 100%. What can I do to prevent the UI freeze?
Beta Was this translation helpful? Give feedback.
All reactions