I was looking for this. How to share multiple states in context using useContext.
I thought about passing value as
{[firstState, setFirstState, secondState, setSecondState]}
This works but it was very ugly when I deconstructed it inside a child component. Your way is way more elegant, thank you!
@nazmifeeroz nice approach on how to decouple multiple stores with useState, I had a similar approach but instead used reducers in a similar way as Redux.
As you metioned @pazsea , with useState get complicated quickly.
As I was solving similar issues in the past, recently I wrote a tutorial on how to use Context and that code is decoupled with similar structure as Redux you can have a look here: frontendbyte.com/how-to-use-react-...
Of course I would be happy to know if it was helpful too.
Cheers,
Andrea
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I was looking for this. How to share multiple states in context using useContext.
I thought about passing value as
{[firstState, setFirstState, secondState, setSecondState]}
This works but it was very ugly when I deconstructed it inside a child component. Your way is way more elegant, thank you!
@nazmifeeroz nice approach on how to decouple multiple stores with useState, I had a similar approach but instead used reducers in a similar way as Redux.
As you metioned @pazsea , with useState get complicated quickly.
As I was solving similar issues in the past, recently I wrote a tutorial on how to use Context and that code is decoupled with similar structure as Redux you can have a look here: frontendbyte.com/how-to-use-react-...
Of course I would be happy to know if it was helpful too.
Cheers,
Andrea