1 min readFeb 17, 2019
Thank you for the question.
When using redux you:
- dispatch an action
- the reducer changes its state
- the props of Component changes because it is connected (subscribed) to that state. (using
{ connect } from 'react-redux'
) - therefore the Component re-renders
With the method shown in this article you:
- call
store.set
- the value of the Context.Provider changes
- this causes the re-render of its children (only the children that have Context.Consumer)
This means that:
- using Redux the action/reducer/store “flow” is faster, but then you have to wait for the re-rendering of the Component. In other words, the redux action and reducer functions finish faster, then you have to wait for the Component render method to finish.
- Using this article method the
store.set
“flow” is slower, but the Component is already re-rendered. Thestore.get
function finishes when the Component render method is finished
The point is that any time the value of the Context.Provider changes, this causes the re-render of its children. This has to be kept in mind to avoid useless re-render when using Context API.
I’m updating the website of the project react-store
to add a performance page where this concept is shown in action. I’ll notify you as soon as it’s ready.
I Hope I answered the question.