CacheStore rerender behaviour #2673
studioradiaal
started this conversation in
Ideas
Replies: 1 comment 3 replies
-
Thanks for posting here. A few questions on your use case:
These questions will help me better grasp what solutions may best suite this use case |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I am using rest-hooks in a ReactJS project, to visualize and control the status of an audio processing device. The device provides both a REST API and an async/websocket API. The websocket is used to receive notifications when parameters change, to avoid excessive polling. One of the main uses for the websocket is periodic updates of audio levels (every 40ms), to show on level meters in the UI.
I implemented a StreamManager, based on the description in the docs: https://resthooks.io/docs/api/Manager#data-stream. The level meters are always visible in the UI, so the StreamManager does controller.setResponse with the levels every 40ms. This causes the CacheStore to be updated at the same rate, which in turns rerenders EVERY component that uses the useLive hook, even if they use totally unrelated data. Some of those unneeded renders are quite expensive, resulting in a laggy UI.
So my question is: is there a way to prevent rerenders of components when their corresponding data has not changed? Ideally, I would want to implement this "globally" in the rest-hooks setup/configuration, or in the StreamManager, or on the endpoint of the fast-changing data, or ...
Preferably I don't want to change all slow-changing components/endpoints.
Hopefully you can give me some options or ideas to look at. Thanks.
(Note: I originally asked this question on the ask-rest-hooks Discord channel. At the request of the library maintainer, I started this discussion here).
Beta Was this translation helpful? Give feedback.
All reactions