[Redux] Using mapDispatchToProps() Shorthand Notation
Using redux
2023-09-14 08:59:19 时间
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));
相关文章
- C#中using语句是什么意思「建议收藏」
- ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
- 深度理解Redux原理并实现一个redux_2023-02-28
- Device-Free Gesture Tracking Using Acoustic Signals
- ORA-19768: USING clause only valid with ENABLE CHANGE TRACKING ORACLE 报错 故障修复 远程处理
- ORA-23389: obsolete procedure; drop objects and recreate using new master ORACLE 报错 故障修复 远程处理
- ORA-64108: Cannot truncate a table that has an XMLIndex whose internal table has been indexed using Oracle Text. ORACLE 报错 故障修复 远程处理
- MySQL Error number: MY-011241; Symbol: ER_XPLUGIN_USING_SSL_CONF_FROM_MYSQLX; SQLSTATE: HY000 报错 故障修复 远程处理
- exportExporting Data from MySQL Using the STMT Command(stmtmysql)
- Exploring the Benefits of Using htonl Function in Linux Networking(linuxhtonl)
- Exploring the World of Linux with Ease: A Guide to Using Aoyou(遨游forlinux)
- Exploring the Benefits of Using MySQL INT for Database Storage and Retrieval(mysqlint)