redux与redux-react使用示例
redux使用
- <script type="text/babel">
- var Counter=React.createClass({
- incrementIfOdd:function(){
- if (this.props.value % 2 !== 0) {
- this.props.onIncrement();
- }
- },
- incrementAsync:function() {
- setTimeout(this.props.onIncrement, 1000);
- },
- render:function() {
- const { value, onIncrement, onDecrement } = this.props;
- return (
- <p>
- Clicked: {value} times
- {' '}
- <button onClick={onIncrement}>
- +
- </button>
- {' '}
- <button onClick={onDecrement}>
- -
- </button>
- {' '}
- <button onClick={this.incrementIfOdd}>
- Increment if odd
- </button>
- {' '}
- <button onClick={this.incrementAsync}>
- Increment async
- </button>
- </p>
- )
- }
- });
- function counter(state, action) {
- if (typeof state === 'undefined') {
- return 0
- }
- switch (action.type) {
- case 'INCREMENT':
- return state + 1
- case 'DECREMENT':
- return state - 1
- default:
- return state
- }
- }
- var store = Redux.createStore(counter)
- function render(){
- ReactDOM.render(
- <div><Counter value={store.getState()} onIncrement={function(){store.dispatch({ type: 'INCREMENT' })}} onDecrement={function(){store.dispatch({ type: 'DECREMENT' })}}/></div>,
- document.body
- );
- }
- $(document).ready(function(){
- render();
- store.subscribe(render);
- });
- </script>
redux使用
redux-react使用
- <script type="text/babel">
- var Counter=React.createClass({
- incrementIfOdd:function(){
- if (this.props.value % 2 !== 0) {
- this.props.onIncrement();
- }
- },
- incrementAsync:function() {
- setTimeout(this.props.onIncrement, 1000);
- },
- render:function() {
- const { value, onIncrement, onDecrement } = this.props;
- return (
- <p>
- Clicked: {value} times
- {' '}
- <button onClick={onIncrement}>
- +
- </button>
- {' '}
- <button onClick={onDecrement}>
- -
- </button>
- {' '}
- <button onClick={this.incrementIfOdd}>
- Increment if odd
- </button>
- {' '}
- <button onClick={this.incrementAsync}>
- Increment async
- </button>
- </p>
- )
- }
- });
- function counter(state, action) {
- if (typeof state === 'undefined') {
- return 0
- }
- switch (action.type) {
- case 'INCREMENT':
- return state + 1
- case 'DECREMENT':
- return state - 1
- default:
- return state
- }
- }
- var store = Redux.createStore(counter)
- function render(){
- var TESTCounter=ReactRedux.connect(function(state, ownProps){
- return {value:state}
- },function(dispatch, ownProps){
- return Redux.bindActionCreators({
- onIncrement:function(){return { type: 'INCREMENT' }}
- ,
- onDecrement:function(){
- return { type: 'DECREMENT' };
- }
- },dispatch)
- })(Counter);
- ReactDOM.render(
- <div><ReactRedux.Provider store={store}>
- <TESTCounter />
- </ReactRedux.Provider></div>,
- document.body
- );
- }
- $(document).ready(function(){
- render();
- });
- </script>
redux-react使用
记录以防忘记
redux与redux-react使用示例的更多相关文章
- 基于 React.js + Redux + Bootstrap 的 Ruby China 示例 (转)
一直学 REACT + METEOR 但路由部分有点问题,参考一下:基于 React.js + Redux + Bootstrap 的 Ruby China 示例 http://react-china ...
- Redux:with React(一)
作者数次强调,redux和React没有关系(明明当初就是为了管理react的state才弄出来的吧),它可以和其他插件如 Angular, Ember, jQuery一起使用.好啦好啦知道啦.Red ...
- React - redux, jsx中写js示例
{ this.state.avatarSource === null ? <Text>Select a Photo</Text> : <Image style={styl ...
- [转] What is the point of redux when using react?
As I am sure you have heard a bunch of times, by now, React is the V in MVC. I think you can think o ...
- [Redux] Filtering Redux State with React Router Params
We will learn how adding React Router shifts the balance of responsibilities, and how the components ...
- [Redux] Navigating with React Router <Link>
We will learn how to change the address bar using a component from React Router. In Root.js: We need ...
- 25.redux回顾,redux中的action函数异步
回顾:Redux: 类似于 Vuex 概念:store/reducer/action action:动作 {type,.....} 一定要有type 其他属性不做限制 reducer:通过计算产生st ...
- React-安装和配置redux调试工具Redux DevTools
chrome扩展程序里搜索Redux DevTools进行安装 新建store的时候,进行如下配置. import { createStore, applyMiddleware ,compose} f ...
- Redux 和 Redux thunk 理解
1: state 就像 model { todos: [{ text: 'Eat food', completed: true }, { text: 'Exercise', completed: fa ...
- [Redux] Understand Redux Higher Order Reducers
Higher Order Reducers are simple reducer factories, that take a reducer as an argument and return a ...
随机推荐
- Zookeeper .Net客户端代码
本来此客户端可以通过NuGet获取,如果会使用NuGet, 则可以使用命令Install-Package ZooKeeperNet(需要最新版本的NuGet) 如果不会,就去 NuGet官网了解htt ...
- 识别简单的答题卡(Bubble sheet multiple choice scanner and test grader using OMR, Python and OpenCV——jsxyhelu重新整编)
该博客转自www.pyimagesearch.com,进行了相关修改补充. Over the past few months I've gotten quite the number of reque ...
- django基础 -- 5. ORM 数据库操作
一. ORM 对象关系映射 类 ------ 表 类对象 ------ 记录 类属性 ------ 字段 二. 连接数据库配置 1.在 setting.py 文件中重新设置 ...
- Java——List:list.add(index, element)和list.set(index, element)的区别
add(index, element) 含义:在集合索引为index的位置上增加一个元素element,集合list改变后list.size()会增加1 用法 testList.add(index, ...
- Python3基础 list pop(含参) 取出列表中的指定索引的元素
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- awk - group adjacent rows by identical columns
Liang always brings me interesting quiz questions. Here is one: If i have a table like below: chr1 1 ...
- spring注解预览
从Java5.0开始,Java开始支持注解.Spring做为Java生态中的领军框架,从2.5版本后也开始支持注解.相比起之前使用xml来配置Spring框架,使用注解提供了更多的控制Spring框架 ...
- Linux let 命令
命令:let let 命令是 BASH 中用于计算的工具,用于执行一个或多个表达式,变量计算中不需要加上 $ 来表示变量.如果表达式中包含了空格或其他特殊字符,则必须引起来. 语法格式 let arg ...
- 【Python】【数据库】
#[[数据库]]'''MySQL是Web世界中使用最广泛的数据库服务器.SQLite的特点是轻量级.可嵌入,但不能承受高并发访问,适合桌面和移动应用.而MySQL是为服务器端设计的数据库,能承受高并发 ...
- _event_phase_team
EventId 事件ID Phase 阶段ID,从1开始 TeamId 事件玩家分组,攻守(防守为1,进攻为2),自定义阵营(_faction表自定义阵营ID),公会(公会guid) Graveyar ...