Sitemap
1 min readFeb 17, 2019

Thank you for the question.

When using redux you:

  1. dispatch an action
  2. the reducer changes its state
  3. the props of Component changes because it is connected (subscribed) to that state. (using { connect } from 'react-redux')
  4. therefore the Component re-renders

With the method shown in this article you:

  1. call store.set
  2. the value of the Context.Provider changes
  3. 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. The store.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.

Lorenzo Spyna
Lorenzo Spyna

Written by Lorenzo Spyna

💻Writes web2 and web3 code | 🚀 firenze.dev co-founder | 🥑 0xpolygon Advocate — https://spyna.it

Responses (1)