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 ...
随机推荐
- php 一个文件搞定支付宝支付,微信支付
博客:https://me.csdn.net/jason19905 支付宝支付:https://github.com/dedemao/alipay 微信支付:https://github.com/de ...
- Python求最大可能
也称为求一个集合的所有的子集 采用二进制方法: def PowerSetsBinary(items): #generate all combination of N items N = len(ite ...
- PostgreSQL 10首个测试版本发布
mysql 从5.7到8.0,pg从9.6到10,干起来了.. PostgreSQL 10 的首个测试版发布了,此版本包含 PostgreSQL 10 最终将提供的所有功能的预览.当然,有些细节将在最 ...
- python简说(一)if,for等
一.python简说 python可以用于自动化测试.web开发.数据分析.AI python.自动化运维,第三方模块最多的一个语言. 编译型语言 c.c++ 要运行,先要编译,编译成二进制的. 解释 ...
- 一、数据库表中字段的增删改查,二、路由基础.三、有名无名分组.四、多app共存的路由分配.五、多app共存时模板冲突问题.六、创建app流程.七、路由分发.八、路由别名,九、名称空间.十、反向解析.十一、2.x新特性.十二、自定义转换器
一.数据库表中字段的增删改查 ''' 直接在modules中对字段进行增删改查 然后在tools下点击Run manage.py Task执行makemigrations和migrate 注意在执行字 ...
- Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)
centos7.5 安装mysql数据库报错 问题: [root@db04-54 scripts]# /etc/init.d/mysqld start /etc/init.d/mysqld: line ...
- Selenium Java Selection的使用
用于向具有drop-down的选择框中输入内容 new Select(new ChromeDriver().findElement(By.cssSelector(" ..."))) ...
- topcoder srm 300 div1
problem1 link 直接模拟即可. import java.util.*; import java.math.*; import static java.lang.Math.*; public ...
- 如何安装整个linux系统中所需要的mp3播放库插件? 可以在安装rpmfusion仓库后直接通过dnf install进行按照就可以了
在vi的界面中, 前面的数字, 表示一行. 而对于中文而言, 并不一定是"一个文本行"就是一行, 而是以 回车(硬回车)为标志, 来判定一行的. 而dd, yy等也是以" ...
- SpringBoot 全局统一记录日志
1.记录日志 使用aop来记录controller中的请求返回日志 pom.xml引入: <dependency> <groupId>org.springframework.b ...