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));

[Redux] Using mapDispatchToProps() Shorthand Notation的更多相关文章

  1. PRML读书笔记——Mathematical notation

    x, a vector, and all vectors are assumed to be column vectors. M, denote matrices. xT, a row vcetor, ...

  2. redux学习日志:关于react-redux

    首先先强调一句:一定要多读官方文档,而且要精读,否则你会忽略掉很多东西! 一,Provider 刚开始看的时候,大致浏览了一下,知道了这个组件是能够接收store作为它的属性,然后它里面的子组件就可以 ...

  3. mapStateToProps,mapDispatchToProps的使用姿势

    本文作者:IMWeb 黄qiong 原文出处:IMWeb社区 未经同意,禁止转载 前言 刚接触redux的时候,发现大家对mapDispatchToProps使用有几种方法,而且都跑通了,本文来介绍下 ...

  4. 你要的 React 面试知识点,都在这了

    摘要: 问题很详细,插图很好看. 原文:你要的 React 面试知识点,都在这了 作者:前端小智 Fundebug经授权转载,版权归原作者所有. React是流行的javascript框架之一,在20 ...

  5. react 面试指南

    ------------恢复内容开始------------ 什么是声明式编程 声明式编程是一种编程范式,它关注的是你要做什么,而不是如何做.它表达逻辑而不显式地定义步骤.这意味着我们需要根据逻辑的计 ...

  6. Struts2核心技术简介

    Struts2核心技术简介 使用Struts2框架,只要注重以下三大元素:配置文件.映射文件和Action: 全局属性文件struts.properties:保存系统运行的一些参数变量,整个系统只有一 ...

  7. Control Flow

    1.重写折半查找,使得在循环内部只执行一次测试 传统的非递归式的折半查找的例子中,while循环语句内部共执行了两次测试,其实只要一次就足够(代价是将更多的测试在循环外执行).重写该函数,使得在循环内 ...

  8. Struts2中的 配置文件

    struts2中涉及到的配置文件有: web.xml.struts.xml.struts.properties.default.properties.struts-default.xml web.xm ...

  9. Activating Browser Modes with Doctype

    原文地址:https://hsivonen.fi/doctype/ In order to deal both with content written according to Web standa ...

随机推荐

  1. iOS之手势滑动返回功能-b

    iOS中如果不自定义UINavigationBar,通过手势向右滑是可以实现返回的,这时左边的标题文字提示的是上一个ViewController的标题,如果需要把文字改为简约风格,例如弄过箭头返回啥的 ...

  2. 标签form表单里的属性简单介绍了一下

    <form id="form1" name="form1" method="post" action=""> ...

  3. IE8下String的Trim()方法失效的解决方法

    String的Trim()方法失效,在ie8下是有这样的情况的,解决方法也很简单使用$.trim(str)即可,需要的朋友可以了解下 用jquery的trim()方法,$.trim(str)就可以了.

  4. redis百度百科和维基百科知识总结:

    1. 百度百科知识总结: Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.从2010年3月15日起,Redis ...

  5. 关于entity framework

    http://www.cnblogs.com/lsxqw2004/archive/2009/05/31/1495240.html http://www.open-open.com/lib/view/o ...

  6. zookeeper如何永久监听

    转自:http://www.cnblogs.com/viviman/archive/2013/03/11/2954118.html 一 回调基础知识 znode 可以被监控,包括这个目录节点中存储的数 ...

  7. Android Animation

    Android中常用两种动画模式,tween animation和frame animation,即补间动画和帧动画,但在android3.0中又引入了一个新的动画系统:property animat ...

  8. 17.1.1.6 Creating a Data Snapshot Using Raw Data Files 创建一个数据快照使用 Raw Data Files

    17.1.1.6 Creating a Data Snapshot Using Raw Data Files 创建一个数据快照使用 Raw Data Files 如果数据库是大的, 复制raw 数据文 ...

  9. 17.1.1.2 Setting the Replication Slave Configuration

    17.1.1.2 Setting the Replication Slave Configuration 在一个复制slave, 你必须创建一个唯一的server ID,如果这个没有做,slave设置 ...

  10. 【HDOJ】2473 Junk-Mail Filter

    并查集删除结点,方法是构建虚拟点,做映射. #include <stdio.h> #include <string.h> #define MAXNUM 1000050 int ...