rsmpark / tempo_tester

0 stars 0 forks source link

POC - Multiple Context Providers vs. Redux Store #20

Closed rsmpark closed 11 months ago

rsmpark commented 11 months ago

Currently, when the context is updated any components that consumes appState via context provider will be re-rendered. Metronome.tsx runs into latency issues when playing the click as the re-render caused by the context will force the sound to play.

Solution

Reference

It's because of how the state is encapsulated. In react-redux, state is encapsulated inside a store. When you pass the store to Provider in react-redux - you are using the Context API (see this in react-redux) but here's the kicker - the redux context never changes (in 99% of implementations anyway). So the Consumers of the Redux context will never re-render the way a regular context consumer would (because the value supplied by the context never changes).

https://stackoverflow.com/questions/67254562/the-difference-between-context-api-and-redux

rsmpark commented 11 months ago

References used to create Context API

https://kentcdodds.com/blog/how-to-use-react-context-effectively