Answer the question
In order to leave comments, you need to log in
How to optimize mapDispatchToProps?
In order not to fence in each component like this
const mapDispatchToProps = (dispatch) => {
return {
saveUser: bindActionCreators(saveUserAction, dispatch),
getUser: bindActionCreators(getUserAction, dispatch),
getUser: bindActionCreators(getUserAction, dispatch),
getUser: bindActionCreators(getUserAction, dispatch),
getUser: bindActionCreators(getUserAction, dispatch),
getUser: bindActionCreators(getUserAction, dispatch),
и т.д.
};
};
Answer the question
In order to leave comments, you need to log in
There is a good option: connect actions via *
import * as UserActions from '../actions/UserActions'
...
const mapDispatchToProps = (dispatch) => {
return {
userActions: bindActionCreators(UserActions, dispatch)
}
}
const mapDispatchToProps = (dispatch) => ({
userActions: bindActionCreators(UserActions, dispatch)
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question