RFC: `mapStateToProps` or `mapStoreToProps` naming convention?
See original GitHub issueI’ve taught about 10 people how to use react-redux
at this point and a common sticking point is the use of mapStateToProps
. This seems to be due to confusion in terminology between local state
and the state of the store
.
In teaching these React-newbies, I’ve found that when I describe the mapStateToProps
in terms of mapStoreToProps
, they understand it very quickly, since it’s not immediately clear to them based on the name that the values they’re mapping in mapStateToProps
come from the store
.
I propose changing mapStateToProps
to mapStoreToProps
, as I think it more accurately reflects what the function is doing: it’s selecting values from the store
and mapping them the component’s props.
const mapStoreToProps = store => {
return {
user: store.user
}
}
I realize this is only a superficial change, since the name of the function doesn’t actually affect how connect
uses it, but I think it might make it easier for React-newbies to understand what the function is actually doing.
Thoughts?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:5
- Comments:10 (4 by maintainers)
Top GitHub Comments
This will however be wrong because
store
is a different thing. It’s an object withgetState()
anddispatch()
methods. We can’t refer to store state as store because this is even more confusing. And we can’t pass store itself because we want to hidedipspatch
by design.This is not just a minor issue, but I find that
mapStateToProps
is the first real stumbling block for people learning redux - and that’s not because of them but because it’s a really bad naming decision for something used in react-redux.I’m teaching my students
mapReduxStateToProps()
, but that’s just one of various solutions. So independent of what the solution is, can we start with all acknowledging thatmapStateToProps
is letting beginners down?