Before you use the React Redux bindings, learn how to create a complete simple application with just React and Redux.

<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.0.4/redux.js"></script>
<script src="https://fb.me/react-0.14.0.js"></script>
<script src="https://fb.me/react-dom-0.14.0.js"></script> </head>
<body>
<div id='root'></div>
</body>
</html>
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
} const Counter = ({
value,
onIncrement,
onDecrement
}) => (
<div>
<h1>{value}</h1>
<button onClick={onIncrement}>+</button>
<button onClick={onDecrement}>-</button>
</div>
); const { createStore } = Redux;
const store = createStore(counter); const render = () => {
ReactDOM.render(
<Counter
value={store.getState()}
onIncrement={() =>
store.dispatch({
type: 'INCREMENT'
})
}
onDecrement={() =>
store.dispatch({
type: 'DECREMENT'
})
}
/>,
document.getElementById('root')
);
}; store.subscribe(render);
render();

From React 0.14, you can declear a compoment by using a function.

[Reduc] React Counter Example的更多相关文章

  1. [Recompose] Merge RxJS Button Event Streams to Build a React Counter Component

    Combining input streams then using scan to track the results is a common scenario when coding with s ...

  2. RxJS + Redux + React = Amazing!(译一)

    今天,我将Youtube上的<RxJS + Redux + React = Amazing!>翻译(+机译)了下来,以供国内的同学学习,英文听力好的同学可以直接看原版视频: https:/ ...

  3. 2017-1-5 天气雨 React 学习笔记

    官方example 中basic-click-counter <script type="text/babel"> var Counter = React.create ...

  4. react+redux教程(六)redux服务端渲染流程

    今天,我们要讲解的是react+redux服务端渲染.个人认为,react击败angular的真正“杀手锏”就是服务端渲染.我们为什么要实现服务端渲染,主要是为了SEO. 例子 例子仍然是官方的计数器 ...

  5. zepto/jQuery、AngularJS、React、Nuclear的演化

    写在前面 因为zepto.jQuery2.x.x和Nuclear都是为现代浏览器而出现,不兼容IE8,适合现代浏览器的web开发或者移动web/hybrid开发.每个框架类库被大量用户大规模使用都说明 ...

  6. 前端自动化测试 —— TDD环境配置(React+TypeScript)

    欢迎讨论与指导:) 前言 TDD -- Test-Drive Development是测试驱动开发的意思,是敏捷开发中的一项核心实践和技术,也是一种测试方法论.TDD的原理是在开发功能代码之前,先编写 ...

  7. react+redux教程(四)undo、devtools、router

    上节课,我们介绍了一些es6的新语法:react+redux教程(三)reduce().filter().map().some().every()....展开属性 今天我们通过解读redux-undo ...

  8. react+redux教程(一)connect、applyMiddleware、thunk、webpackHotMiddleware

    今天,我们通过解读官方示例代码(counter)的方式来学习react+redux. 例子 这个例子是官方的例子,计数器程序.前两个按钮是加减,第三个是如果当前数字是奇数则加一,第四个按钮是异步加一( ...

  9. React官网学习笔记

    欢迎指导与讨论 : ) 前言 本文主要是笔者在React英文官网学习时整理的笔记.由于笔者水平有限,如有错误恳请指出 O(∩_∩)O 一 .Tutoial 篇 1 . React的组件类名的首字母必须 ...

随机推荐

  1. Swift - 07 - 布尔类型

    //: Playground - noun: a place where people can play import UIKit var str = "Hello, playground& ...

  2. 使用GitBook编写文档

    GitBook 简介 GitBook 是一个通过 Git 和 Markdown 来撰写书籍的工具,最终可以生成 3 种格式: 静态站点:包含了交互功能(例如搜索.书签)的站点 PDF:PDF 格式的文 ...

  3. jqgrid设置单元格数据

    $("#gridid").jqGrid('setCell',rowid,icol,data); rowid为行ID,jqgrid内置的那个,从1开始 icol为列索引,从0开始, ...

  4. 常用排序算法总结(C#版)

    首先,说说几个排序中的概念. 1.稳定排序和非稳定排序  简单地说就是所有相等的数经过某种排序方法后,仍能保持它们在排序之前的相对次序,我们就说这种排序方法是稳定的.反之,就是非稳定的. 比如:一组数 ...

  5. TP开发小技巧

    TP开发小技巧原文地址http://wp.chenyuanzhao.com/wp/2016/07/23/tp%E5%BC%80%E5%8F%91%E5%B0%8F%E6%8A%80%E5%B7%A7/ ...

  6. nginx 伪静态大于10个参数 $10

    伪静态大于10个参数   会解析成 $1   与 0 参考:http://zhidao.baidu.com/link?url=kT2tp8ARhIZsrt4XF3LdzjkEq0QTIbvhOj9Ck ...

  7. jquery ajax(4).getjson()

    .getJSON()实例 .each()实例 $(function(){ $('#send').click(function() { $.getJSON('test.json', function(d ...

  8. 探究Android中Listview显示错乱问题

    问题 最近在项目中遇到过一个很棘手的问题,就是ListView在滑动后就莫名其妙的显示错乱,网上查阅资料后问题很容易的就解决了,但是对于问题产生的原因仍是一知半解,所以不甘心的我定下心来,狠读源码,终 ...

  9. 转:Asp JSONP 实践

    我用asp做服务端客户端 客户端页面首先在body 中放置一个div: <div id="res"></div> 将远程调用的数据写入该div中 <s ...

  10. NTOPNG,用来平时优化网站性能,用处大的

    最近考察一下NTOPNG和NGX-REQ模块,看哪个对网站优化性能用户更大... 参考URL: http://www.68idc.cn/help/jiabenmake/qita/20150109164 ...