DEV Community

Cover image for Redux in 27 lines

Redux in 27 lines

selbekk on March 21, 2019

Redux has become the defacto standard for state management in React. It's a great tool for handling global state, and its sheer popularity means yo...
Collapse
 
theodesp profile image
Theofanis Despoudis

Sometimes less is more...

Collapse
 
sebastiandg7 profile image
Sebastián Duque G

I would say 'most of the times'.

Collapse
 
lucassorenson profile image
lucassorenson

Thanks for a very helpful article. I have dabbled with Redux before, and while I think I had a decent grasp of the concept, seeing how it actually works, and how simple the mechanisms are really makes it a lot easier to wrap my head around.

Collapse
 
pigozzifr profile image
Francesco Pigozzi

Great article! I never dived deep into Redux's core logic but this is really fascinating.

Would you mind checking my last article about middlewares? Maybe you can give me some good advices!

dev.to/pigozzifr/lets-play-with-re...

Collapse
 
kevinmduffey profile image
Kevin Duffey

Last time I played with Redux, there was the concept of smart and dumb components, and smart components had to be connected to Redux. Your article seems to indicate just adding subscribers, which is slick.. but.. how do you manage re-rendering only components that are connected to stores/actions so that for example, you can have a component (or subset of components) re-render only when a specific action/state occurs, and not have the state call all subscribers on all changes? Is that no longer the way Redux works? Or is that more advanced and this intro was to keep it simple?

Collapse
 
selbekk profile image
selbekk • Edited

This intro is actually pretty framework agnostic - talking about how Redux is implemented, not how it connects to React.

That being said, the way the connect method from react-redux works is by subscribing on mount, unsubscribing on unmount, and implementing a clever shouldComponentUpdate based on the output of your mapStateToProps method. You could create a similar HOC with this implementation, too!

Collapse
 
sebbdk profile image
Sebastian Vargr • Edited

For anyone interested in redux, reading the source really is a great way to see what it can do.

It is surprisingly small, and fast to read through, as this article indicates. :)

Collapse
 
dance2die profile image
Sung M. Kim

I love the process of what Redux is and how to implement it step by step as it helps understand how Redux works 🙂

Collapse
 
chadsteele profile image
Chad Steele

I'd love it if you wanted to dissect my Redux one line replacement hook... useSync
dev.to/chadsteele/redux-one-liner-...

Collapse
 
ardiaankur profile image
Ankur Gupta

It was a nice explanation in simple words. hats off. but I would like to touch more on enhancers. Still have some doubts on its implementation.