Feature request use mapStateToProps in mapDispatchToProps
See original GitHub issueHello
First of all I would thank you for this awesome library been using it in all my projects lately!
There is just one thing that is bugging me. I often would like to use the state props I pick from the mapStateToProps
in mapDispatchToProps
. Right now I use a library called recompose
and a hoc called withHandlers
to do this.
Example how I do today.
compose(
connect(
(state) => ({
someProp: state.someState,
}),
(dispatch) => ({
onSomeAction: (someProp) => dispatch(someAction(someProp)),
}),
),
withHandlers({
onSubmit: ({ someProp, onSomeAction }) => (e) => {
e.preventDefault();
onSomeAction(someProp);
},
}),
)(DumbComponent);
Suggested feature.
connect(
(state) => ({
someProp: state.someProp,
}),
(dispatch) => ({
// If the dispatch prop is executed and returns a functions then run that function automatically with the latest props
onSubmit: ({ someProp }) => (e) => {
e.preventDefault();
dispatch(someAction(someProp));
},
}),
)(DumbComponent);
Issue Analytics
- State:
- Created 6 years ago
- Comments:17 (11 by maintainers)
Top Results From Across the Web
mapStateToProps and mapDispatchToProps: getting IDE ...
I haven't been using React recently. As for a solution, see the original question under "Motivation". That workaround allows for IDE code ...
Read more >You Might Not Need The mapDispatchToProps Function
First, a mapStateToProps function that plucks pieces of state out of Redux and assigns them to props that your React component will use....
Read more >Connect: Extracting Data with mapStateToProps
As the first argument passed in to connect , mapStateToProps is used for selecting the part of the data from the store that...
Read more >Use Redux with React
Both mapStateToProps and mapDispatchToProps are optional and can be omitted as necessary. If you're using a selector that is produced through a factory, ......
Read more >Demystifying 15 lesser-known React Redux terms and ...
Compromises of using Redux over Flux. Difference between mapStateToProps and mapDispatchToProps. Dispatching action in the reducer.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’d just use the
getState
arg in redux-thunk, personally. Way more testable that way.Mmm… I may be mixing up cases in my head between using the object shorthand and using an actual
mapDispatch
function. I’ll have to look at this again later.I still stand by my point that I don’t think this is worth another edge case.