react 控制 tabbar 显示/隐藏

react-redux 将 store 绑定到 props 上,便于全局调用。

redux-saga 是将 redux 的同步转换为异步。

注:

dispatch 到 saga , saga 匹配行为的 type,调用接口请求数据,并将数据 通过 dispatch 传给 redux。

redux 匹配 type 并将数据绑定到 props 上

思路:

(1)routes 下的页面触发 action

this.props.dispatch({
  type:"xxx", // 行为名称
  payload: yyy
})

(2)saga 下的异步 redux 进行匹配

找到对应的 fork(reducer)

在 reducer 中调用整体的也是唯一的 action

yield takeLatest("xxx",(yyy) => functionName(yyy))

在 functionName 中使用 put 代替 dispatch

yield put({
  type:"aaa", // 数据type
  payload: bbb
})

(3)redux 下的同步 redux 进行匹配

找到对应的 reducer

在 reducer 中进行 type 匹配

case 匹配 type , return 出去的数据 需要 先 

const initstate = { ccc: ddd }

初始化。

将获取的 数据 return 到 props 上

(4)全局获取 store 上的数据

const { ccc } = this.props;

.

猜你喜欢

转载自www.cnblogs.com/crazycode2/p/9256863.html