DEV Community

Discussion on: React Context without Provider + useMutableSource

Collapse
windmaomao profile image
Fang Jin

Thanks for this article. And I just wonder, if I don't want to use redux, can I use this approach for any "global" state? I'm aware that react-redux uses this internally.

Currently hook stores the memorized state locally under each fiber. With this approach, I wonder where the store is placed.

Thanks for sharing.

Collapse
aslemammad profile image
M. Bagher Abiat Author

Thank you, Fang, you made my day. Yes, you can use this approach, And I use it in my projects. Or you can use the better version of it, which we work on, jotai.
github.com/pmndrs/jotai

The store lives in a simple object, but we attach some useStates to it basically when we use uMS, so when it changes, we call those useStates(setStates) in the components. So no wasteful renders like React Context. Just your subscribed component is going to be changed.

github.com/reactjs/rfcs/blob/maste...
github.com/reactwg/react-18/discus...

Collapse
windmaomao profile image
Fang Jin

thanks for the quick reply man, i actually came from the RFC page :)

will take a close look at article you forwarded and jotai. Always interested at some localized version of redux. Thank you.

Thread Thread
aslemammad profile image
M. Bagher Abiat Author

Yes, I appreciate it. I recommend you take a look at the simulated version which I gave the link in the article. It's a good alternative to the experimental one.