[Redux] Using mapDispatchToProps() Shorthand Notation

We will learn how to avoid the boilerplate code in mapDispatchToProps() for the common case where action creator arguments match the callback prop arguments.

Current code:

// visibleTodoList.js
const mapDispatchToProps = (dispatch) => {
return {
onTodoClick: (id) => {
dispatch(toggleTodo(id));
},
};
}; const VisibleTodoList = withRouter(connect(
mapStateToProps,
mapDispatchToProps
)(TodoList));

The id we pass from onTodoClick is the same as in toggleTodo, then we can use the shorthard notation to get rid of mapDispatchToProps function:

const VisibleTodoList = withRouter(connect(
mapStateToProps,
{onTodoClick: toggleTodo}
)(TodoList));
上一篇:使用Xshell在Windows系统和Linux系统之间进行文件传输


下一篇:在windows系统和kali中通过sqlmap注入