0 votes
in ReactJS by

What are the different ways to write mapDispatchToProps()?

1 Answer

0 votes
by

There are a few ways of binding action creators to dispatch() in mapDispatchToProps(). Below are the possible options:

const mapDispatchToProps = (dispatch) => ({
 action: () => dispatch(action())
})
const mapDispatchToProps = (dispatch) => ({
 action: bindActionCreators(action, dispatch)
})
const mapDispatchToProps = { action }

The third option is just a shorthand for the first one.

Related questions

0 votes
asked Oct 7, 2019 in Bootstrap by Tracy Williams
0 votes
asked Oct 22, 2023 in JavaScript by DavidAnderson
...