DEV Community

Discussion on: Build a Redux-like Global Store Using React Hooks

Collapse
 
ramsay profile image
Ramsay

Hi Brendan! In production at work, we have actually moved dispatch into its own context and have a useDispatch and useStore hook. Usually, components needed to dispatch actions don't generally need to use the state itself. This will probably cut down on a lot of the re-renders you're seeing.

Another option for possibly reducing the amount of calls would be to create a "hydrate store" action that does all the initial loading of state you need in one action. I'm not sure how feasible this is in your project, but its something we're doing as well.

Collapse
 
visarts profile image
Brendan B

Thanks for the reply! This definitely gives me something to chew on

Collapse
 
juwdohr profile image
Juwdohr

Ramsay, loved your Article. I actually was able to follow it and implement it on something that I have been working on. Wondering you how you would have created the useDispatch and the "hydrate store" action?