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 ...
随机推荐
- Tensorflow学习笔记01
Tensorflow官方网站:http://tensorflow.org/ 极客学院Tensorflow中文版:http://wiki.jikexueyuan.com/project/tensorfl ...
- P2336 [SCOI2012]喵星球上的点名(后缀自动机+莫队+dfs序)
P2336 [SCOI2012]喵星球上的点名 名字怎么存?显然是后缀自动机辣 询问点到多少个喵喵喵其实就是 查询后缀自动机上parent树的一个子树 于是我们考虑莫队 怎么树上莫队呢 我们用dfs序 ...
- P1382 楼房
P1382 楼房 每个矩形拆成2个坐标按$x$轴排序,蓝后$multiset$维护最高值. #include<iostream> #include<cstring> #incl ...
- uml类图和er图中主外键的表示区别
在er图也就是数据库中,无论是mysql/oracle都是从表引用主表的pk作为外键. 而在uml类图表示法中,他们的顺序则刚好相反,从主对象导向到子对象,如下: 主体是资金借款方,征信信息和资金借款 ...
- win7 powershell配色方案
首先我是参考微软的word的, look~ Windows PowerShell 配置文件 要配置powershell很简单, 就几步 1.显示 Windows PowerShell 配置文件的路径 ...
- Android之数据存储之SharedPreferences
SharedPreferences是以键值对形式存储数据,主要用于记录系统的设置,如飞行模式是否开启,声音大小的值等.//SharedPreferences方式保存到xml文件SharedPrefer ...
- noip模拟题 2017.10.28 -kmp -Tarjan -鬼畜的优化
题目大意 给定A串,选择A串的前lB个字符作为B串,再在B串后增加一个字符,问最长的相等的A串前缀和B串的后缀. Solution 1(KMP) 用1个奇怪的字符连接A串和B串,再用KMP求最长公共前 ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem E (Codeforces 831E) - 线段树 - 树状数组
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this int ...
- Oracle SQL——inner jion;left join;right join的区别和使用场景
背景 在一次面试的时候,面试官让我说一下这三者的使用场景和区别,当时瞬间懵逼,哈哈.回来赶快看一看,记下来. 详解 inner join 等值查询:返回两张表中,联结字段值相等的组合记录 举例:所有学 ...
- FireMonkey 源码学习(6)
(6)GetGlyph和GetBaseline TFontGlyphManager是一个抽象类,在不同平台上的实现是不同的,以Windows为例,在FMX.FontGlyphs.Win.pas文件中定 ...