Reputation: 4956
I need to dispatch two actions when submit button is pressed.
const mapDispatchToProps = dispatch => ({
onSubmitPressed: countryCode => dispatch(createCountry(countryCode)),
onSubmitPressed: countryCode => dispatch(loadCountry(countryCode)),
});
The above code works but gives a warning
Duplicate key 'onSubmitPressed'
How to modify the code to map both dispatch actions to single prop without duplicating the key.
Upvotes: 1
Views: 284
Reputation: 578
I'm definitely not sure about this, but it probably works
const mapDispatchToProps = dispatch => ({
onSubmitPressed: countryCode => {
dispatch(createCountry(countryCode));
dispatch(loadCountry(countryCode));
}
});
Upvotes: 0
Reputation: 1805
I don't think this is the best way to do this but if you need it that way I think that might do the trick:
const mapDispatchToProps = dispatch => ({
onSubmitPressed: (countryCode) => {
dispatch(createCountry(countryCode));
dispatch(loadCountry(countryCode));
}
});
Upvotes: 0
Reputation: 85112
const mapDispatchToProps = dispatch => ({
onSubmitPressed: countryCode => {
dispatch(createCountry(countryCode));
dispatch(loadCountry(countryCode));
}
});
Upvotes: 1