loading...

re: Redux VS React Context: Which one should you choose? VIEW POST

FULL DISCUSSION
 

Excellent article ... this sentence jumped out to me:

"But with a more complex state which has high-frequency updates, the React Context won't be a good solution. Because, the React Context will trigger a re-render on each update, and optimizing it manually can be really tough."

I had a deja vue when reading this - this is not the first time I've come across the fact that Redux (especially the "connect" API) intelligently optimizes rendering ... look at this article which says essentially the same thing:

itnext.io/how-existing-redux-patte...

This article is about using Redux with Connect versus using Redux with the Hook APIs - but I think you can make the same arguments about Redux with Connect versus Context with the Hook APIs.

So that's one thing. Second things is that I see people asserting that Context needs a lot less boiler plate than Redux, however I don't really see that ... even with Context and useReducer you're still writing reducers, actions, and so on - what's the big difference?

The way I see it, both the mental model and the way you program are virtually identical between Redux and Context. When I'm done writing reducers and actions with Context then I'm left with almost the same amount of boiler plate - so what have we gained?

(while Redux as a library is extremely lightweight, AND offers a bunch of advantages and capabilities which Context doesn't)

Code of Conduct Report abuse