
A simple example of React useContext and useReducer Hooks available in React that can be used as a replacement for Redux.
Instead of usi...
For further actions, you may consider blocking this person and/or reporting abuse
While this is a bare state management mechanism, it is not a replacement for redux. Here all components subscribed to the context will rerender when any value in the context changes.
When you use redux, only the components subscribed to that particular state rerenders on state change - even though there is a single global store.
Good point. Is there a way to use something to prevent the subscribed components to rerender if not needed? Thinking about something like memo where it does shallow comparison on props object?
What if the context api is used with reducer? more complex but interesting thing to do.
Well, nice article.
Now, I'm missing the part with async actions...
Some other article I read suggested for better performance to divide the Store context and the Dispatch event context as whenever the context changes all components rerenders. But these dispatch methods shouldn't change over runtime...
@ IDURAR , we use react context api for all UI parts , and we keep our data layer inside redux .
Here Article about : 🚀 Mastering Advanced Complex React useContext with useReducer ⭐ (Redux like Style) ⭐ : dev.to/idurar/mastering-advanced-c...
That's awesome. I myself don't really like Redux and I recently used a similar solution in one of my applications. When using Websocket, this is a game changer.
Thanks. Yes, React is evolving pretty good by reducing the dependencies on other libraries. Will post a new featured article about the latest changes very soon.
Really helpful
Thanks a lot for sharing 💖
Good read.
Question: what is the cons and pros between using useReducer with Context API vs using simple useState hook?
useState is not recommended for storing object state