Hacker News new | ask | show | jobs
by presentation 1510 days ago
I don't get why most projects need Redux when React has the context API already. Most people just need a place to store data shared across different components, and plain contexts do that easily.
3 comments

Because Redux and Context are different tools that solve different problems, with some overlap.

Context is a Dependency Injection tool for a single value. Note that it doesn't "manage" or "store" anything - it's just a tube that you can pass something through. Any actual "storage" is normally done with React's own `useState/useReducer` hooks, which actually _do_ store and update values.

Redux, meanwhile, is a tool for predictable state management outside React. Very different kind of tool, for a different purpose.

More details:

https://blog.isquaredsoftware.com/2021/01/context-redux-diff...

They can, but for any reasonable sized application, you're basically recreating bare redux. If someone is good with both, it can architect and choses the correct one based on the needs of your software. But if you find that your global state needs are not small, you just chose redux - add a library like rematch on top to reduce boilerplate - so it's straightforward for your junior.
Out of curiosity, any particular reason you'd suggest Rematch instead of our official Redux Toolkit package?

If you're familiar with both already, are there any parts of Rematch's API you prefer over RTK's, that we should consider looking at for inspiration?

because context re-renders everything all the time