Sign in
Log inSign up
Kunal Keshan

43 likes

·

881 reads

4 comments

Tara Hanson
Tara Hanson
Jan 25, 2023

Nice writeup

1
·
·1 reply
Kunal Keshan
Kunal Keshan
Author
·Jan 25, 2023

Thanks!

·
Sanchit Bajaj
Sanchit Bajaj
Jan 29, 2023

Nice article but I want to ask whether this way of managing states with both useContext and useReducer scalable?

1
·
·1 reply
Kunal Keshan
Kunal Keshan
Author
·Jan 30, 2023

Hey there, thanks!

Sure, the one I've used in this article is limited to a single complex state, so I use two contexts, one for the state and one for the dispatch function.

But if you plan to keep separate states, and retain the global functionality, you can create each context to deliver the state and the dispatch function in the same provider.

This is similar to how the Redux toolkit does, your slices map out to a state with their own reducer functions, only difference is, you have a common dispatch with the redux toolkit.

1
·