为什么使用redux?

共享数据如何使用?

  1. Import { createStore } from ‘redux’
  2. createStore(函数)
  3. dispathch 派发action描述对象的
  4. getState 获取仓库状态的
  5. replaceReducer 替换reducer 仓库的
  6. subscribe 监听仓库状态变化的
  7. reducer 函数中的state参数接收的状态为上一次该reducer函数的返回结果

redux 三个基本原则

  1. 单一数据源
  2. State是只读的
  3. 只能使用纯函数来修改state ;纯函数是什么?

    为什么要用mapDispatchToProps?

  4. 将dispatch相关的操作抽离出视图模块

  5. 整合所有的reducer仓库修改状态的目的

拓展

React.Native 有时间了解一下 用来开发WX小程序的

  • React-redux 实现了组件和redux的桥梁