Code one:
import { addTodo } from "./actionCreators"
import { bindActionCreators } from "redux"
function mapStateToProps(state) {
return { todos: state.todos }
}
function mapDispatchToProps(dispatch) {
return bindActionCreators({ addTodo }, dispatch)
}
export default connect(mapStateToProps, mapDispatchToProps)(TodoApp)
Code 2:
import { addTodo } from "./actionCreators"
function mapStateToProps(state) {
return { todos: state.todos }
}
const mapDispatchToProps = {
addTodo
}
export default connect(mapStateToProps, mapDispatchToProps)(TodoApp)
the role of the above two pieces of code is to inject todos and specific action creation functions. There is a bit of confusion where
code 1 calls bindActionCreators
but not in code 2. The effect of the two pieces of code is the same.
what is the purpose of bindActionCreators
?