redux使用

  1. <script type="text/babel">
  2. var Counter=React.createClass({
  3.  
  4. incrementIfOdd:function(){
  5. if (this.props.value % 2 !== 0) {
  6. this.props.onIncrement();
  7. }
  8. },
  9. incrementAsync:function() {
  10. setTimeout(this.props.onIncrement, 1000);
  11. },
  12. render:function() {
  13. const { value, onIncrement, onDecrement } = this.props;
  14.  
  15. return (
  16. <p>
  17. Clicked: {value} times
  18. {' '}
  19. <button onClick={onIncrement}>
  20. +
  21. </button>
  22. {' '}
  23. <button onClick={onDecrement}>
  24. -
  25. </button>
  26. {' '}
  27. <button onClick={this.incrementIfOdd}>
  28. Increment if odd
  29. </button>
  30. {' '}
  31. <button onClick={this.incrementAsync}>
  32. Increment async
  33. </button>
  34. </p>
  35. )
  36. }
  37. });
  38. function counter(state, action) {
  39. if (typeof state === 'undefined') {
  40. return 0
  41. }
  42.  
  43. switch (action.type) {
  44. case 'INCREMENT':
  45. return state + 1
  46. case 'DECREMENT':
  47. return state - 1
  48. default:
  49. return state
  50. }
  51. }
  52.  
  53. var store = Redux.createStore(counter)
  54. function render(){
  55. ReactDOM.render(
  56. <div><Counter value={store.getState()} onIncrement={function(){store.dispatch({ type: 'INCREMENT' })}} onDecrement={function(){store.dispatch({ type: 'DECREMENT' })}}/></div>,
  57. document.body
  58. );
  59. }
  60.  
  61. $(document).ready(function(){
  62. render();
  63. store.subscribe(render);
  64. });
  65. </script>

redux使用

redux-react使用

  1. <script type="text/babel">
  2. var Counter=React.createClass({
  3.  
  4. incrementIfOdd:function(){
  5. if (this.props.value % 2 !== 0) {
  6. this.props.onIncrement();
  7. }
  8. },
  9. incrementAsync:function() {
  10. setTimeout(this.props.onIncrement, 1000);
  11. },
  12. render:function() {
  13. const { value, onIncrement, onDecrement } = this.props;
  14.  
  15. return (
  16. <p>
  17. Clicked: {value} times
  18. {' '}
  19. <button onClick={onIncrement}>
  20. +
  21. </button>
  22. {' '}
  23. <button onClick={onDecrement}>
  24. -
  25. </button>
  26. {' '}
  27. <button onClick={this.incrementIfOdd}>
  28. Increment if odd
  29. </button>
  30. {' '}
  31. <button onClick={this.incrementAsync}>
  32. Increment async
  33. </button>
  34. </p>
  35. )
  36. }
  37. });
  38.  
  39. function counter(state, action) {
  40. if (typeof state === 'undefined') {
  41. return 0
  42. }
  43.  
  44. switch (action.type) {
  45. case 'INCREMENT':
  46.  
  47. return state + 1
  48. case 'DECREMENT':
  49. return state - 1
  50. default:
  51. return state
  52. }
  53. }
  54.  
  55. var store = Redux.createStore(counter)
  56. function render(){
  57. var TESTCounter=ReactRedux.connect(function(state, ownProps){
  58. return {value:state}
  59. },function(dispatch, ownProps){
  60. return Redux.bindActionCreators({
  61. onIncrement:function(){return { type: 'INCREMENT' }}
  62. ,
  63. onDecrement:function(){
  64. return { type: 'DECREMENT' };
  65. }
  66. },dispatch)
  67. })(Counter);
  68.  
  69. ReactDOM.render(
  70.  
  71. <div><ReactRedux.Provider store={store}>
  72. <TESTCounter />
  73. </ReactRedux.Provider></div>,
  74. document.body
  75. );
  76. }
  77.  
  78. $(document).ready(function(){
  79. render();
  80.  
  81. });
  82. </script>

redux-react使用

记录以防忘记

redux与redux-react使用示例的更多相关文章

  1. 基于 React.js + Redux + Bootstrap 的 Ruby China 示例 (转)

    一直学 REACT + METEOR 但路由部分有点问题,参考一下:基于 React.js + Redux + Bootstrap 的 Ruby China 示例 http://react-china ...

  2. Redux:with React(一)

    作者数次强调,redux和React没有关系(明明当初就是为了管理react的state才弄出来的吧),它可以和其他插件如 Angular, Ember, jQuery一起使用.好啦好啦知道啦.Red ...

  3. React - redux, jsx中写js示例

    { this.state.avatarSource === null ? <Text>Select a Photo</Text> : <Image style={styl ...

  4. [转] 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 ...

  5. [Redux] Filtering Redux State with React Router Params

    We will learn how adding React Router shifts the balance of responsibilities, and how the components ...

  6. [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 ...

  7. 25.redux回顾,redux中的action函数异步

    回顾:Redux: 类似于 Vuex 概念:store/reducer/action action:动作 {type,.....} 一定要有type 其他属性不做限制 reducer:通过计算产生st ...

  8. React-安装和配置redux调试工具Redux DevTools

    chrome扩展程序里搜索Redux DevTools进行安装 新建store的时候,进行如下配置. import { createStore, applyMiddleware ,compose} f ...

  9. Redux 和 Redux thunk 理解

    1: state 就像 model { todos: [{ text: 'Eat food', completed: true }, { text: 'Exercise', completed: fa ...

  10. [Redux] Understand Redux Higher Order Reducers

    Higher Order Reducers are simple reducer factories, that take a reducer as an argument and return a ...

随机推荐

  1. Zookeeper .Net客户端代码

    本来此客户端可以通过NuGet获取,如果会使用NuGet, 则可以使用命令Install-Package ZooKeeperNet(需要最新版本的NuGet) 如果不会,就去 NuGet官网了解htt ...

  2. 识别简单的答题卡(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 ...

  3. django基础 -- 5. ORM 数据库操作

    一. ORM 对象关系映射 类   ------   表 类对象   ------   记录 类属性   ------   字段 二.  连接数据库配置 1.在  setting.py 文件中重新设置 ...

  4. Java——List:list.add(index, element)和list.set(index, element)的区别

    add(index, element) 含义:在集合索引为index的位置上增加一个元素element,集合list改变后list.size()会增加1 用法 testList.add(index, ...

  5. Python3基础 list pop(含参) 取出列表中的指定索引的元素

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  6. 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 ...

  7. spring注解预览

    从Java5.0开始,Java开始支持注解.Spring做为Java生态中的领军框架,从2.5版本后也开始支持注解.相比起之前使用xml来配置Spring框架,使用注解提供了更多的控制Spring框架 ...

  8. Linux let 命令

    命令:let let 命令是 BASH 中用于计算的工具,用于执行一个或多个表达式,变量计算中不需要加上 $ 来表示变量.如果表达式中包含了空格或其他特殊字符,则必须引起来. 语法格式 let arg ...

  9. 【Python】【数据库】

    #[[数据库]]'''MySQL是Web世界中使用最广泛的数据库服务器.SQLite的特点是轻量级.可嵌入,但不能承受高并发访问,适合桌面和移动应用.而MySQL是为服务器端设计的数据库,能承受高并发 ...

  10. _event_phase_team

    EventId 事件ID Phase 阶段ID,从1开始 TeamId 事件玩家分组,攻守(防守为1,进攻为2),自定义阵营(_faction表自定义阵营ID),公会(公会guid) Graveyar ...