DEV Community

Discussion on: Redux in 27 lines

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?

selbekk profile image
selbekk Author • Edited on

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!