You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Although react-redux positioning itself like performant solution for connecting react components to the redux store. However it rerender components on each store state changes synchronously,
that can be an issue, if store changes very frequently(proof). So instead of that we can put component, which should be updated, to the queue and with 60 FPS frequency update each component in queue:
varcomponents=[]// list of all connected components(containers)functiondigest(){for(vari=0;i<components.length;i++){varcomponent=components[i]if(component.shouldHandleStoreStateChange){component.handleChange()}}requestAnimationFrame(digest)}digest()// ...trySubscribe(){if(shouldSubscribe&&!this.unsubscribe){this.unsubscribe=this.store.subscribe(this.queueChanges.bind(this))this.handleChange()components.push(this)}}queueChanges(){this.shouldHandleStoreStateChange=true}handleChange(){// ...this.hasStoreStateChanged=truethis.shouldHandleStoreStateChange=falsethis.setState({ storeState })}
Pros
increases performance up to 1.5x-2.0x and battery live, particularly on mobile devices
But if there is a pitfalls or this solution has no rights to live by another reasons, could you give an advice how to increase performance in this case?
The text was updated successfully, but these errors were encountered:
I wouldn't be comfortable doing something as invasive by default. It makes testing and debugging harder, and introduces potential issues with some browser APIs that expect synchronous updates within an event handler (example: managing an audio tag on iOS).
I would keep it opt in with tools like https://github.com/tappleby/redux-batched-subscribe/. In the future React itself will learn to delay some updates (facebook/react#6170) so longer term this might stop being an issue, and I don't want to break any existing apps that rely on the current synchronous behavior.
Although
react-redux
positioning itself like performant solution for connecting react components to the redux store. However it rerender components on each store state changes synchronously,that can be an issue, if store changes very frequently(proof). So instead of that we can put component, which should be updated, to the queue and with 60 FPS frequency update each component in queue:
Pros
inconsistency with redux after major releases
pure
optionCons
But if there is a pitfalls or this solution has no rights to live by another reasons, could you give an advice how to increase performance in this case?
The text was updated successfully, but these errors were encountered: