React29redux编写一个累加器程序

  • 安装redux       npm install redux --save
  • 编写使用redux的步骤
            《1》从redux引入createStore用来创建仓库store
    • createStore是一个函数,需要传入reducer作为参数,返回值是我们需要的store
            《2》在使用页面引入数据仓库store
    • 通过getState()方法可以获取到数据仓库的状态数据state
    • 通过dispatch(action)可以触发更改reducer函数
    • 每次触发dispatch都会触发store.subscribe()方法,用来重新触发页面渲染
  • 代码展示,对应以上步骤检验
  • store.js        
 
  • FirstRedux.js
  • index.js
 

猜你喜欢

转载自www.cnblogs.com/tengfeiS/p/12169138.html