DEV Community

Discussion on: Throw Out Your React State-Management Tools

Collapse
 
bytebodger profile image
Adam Nathaniel Davis

I agree. And that kinda brings us full circle back to the original point of this particular post. The typical flow seems to go like this:

  1. Team wants to share state.
  2. Team creates global store.
  3. Team starts to realize all the headaches of unplanned use.
  4. Team starts bolting a ton of extra controls on top of the global store to avoid these headaches.
  5. The team's code is now a Frankensteined aberration of what they originally set out to build.

But this is why I'm excited about the Context API. By using that, you can keep full control of that value in its original component. No need to route all changes through a series of actions or reducers. In other words, you can let React's native setState() handle all state updates - just as it was originally designed to do.

It is true that, with the Context API, those value do have to be "exposed". But that should usually be quite painless. In the case of state variables, if you're passing all of state into the ContextProvider's value, there's no need to worry about making future state variables accessible. It's already done.