Community JavaScript Snippet

The mapStateToProps / mapDispatchToProps Cheatsheet I Wish I Had In 2018

Every React + Redux codebase from before hooks revolves around connect. Three accordions of the wiring I keep paged in for inheriting one of those repos.

The mapStateToProps / mapDispatchToProps Cheatsheet I Wish I Had In 2018

Every React + Redux codebase from before hooks revolves around connect. Three accordions of the wiring I keep paged in for inheriting one of those repos.

JavaScript
Frontend
3 snippets
react
design-patterns
state-machine
milozhang

By @milozhang

May 2, 2026

·

Updated May 20, 2026

722 views

8

4.2 (9)

The mental model that finally made connect click for me: think of the connected component as a function of (ownProps + storeSlice + boundActionCreators) -> reactTree. mapStateToProps projects the store down to the slice this view cares about, mapDispatchToProps builds action creators that already know how to call dispatch, and the merged object is what the component sees. The view is a pure function of those merged props, exactly like a hook-based component is a pure function of useSelector plus closed-over dispatchers. The optimisation that connect adds is a shallowEqual check on the produced state-props: the wrapped component only re-renders when one of the projected fields actually changed, which is the entire performance story for large connected apps.