【问题标题】:redux, redux-thunk and re-render UI in theory理论上 redux、redux-thunk 和重新渲染 UI
【发布时间】:2017-07-12 13:50:35
【问题描述】:

我在我的项目中使用 redux,redux-thunk 和 react,这不是实际代码,而是代码的简化版本,因此可能存在一些语法错误,但问题更多的是关于它应该如何工作。

我有使用 react-redux 连接的反应包装器。

在我的操作中,我使用 redux-thunk 如下 -

return function (dispatch, state) {
      dispatch(oneAction);
      dispatch(secondAction);
      dispatch(thirdAction);
}

UI 只在thirdAction 之后渲染,这很好,但我不知道是什么告诉系统现在渲染UI,因为我没有在thirdAction 之后返回数据。

谢谢

【问题讨论】:

    标签: reactjs redux react-redux redux-thunk


    【解决方案1】:

    单独调度操作不会更新 UI。

    首先,reducer 必须侦听分派的操作并更新应用程序在 store 中的状态。

    然后,您的组件(或视图)必须订阅 store 并在 store 更新时更新其本地状态。

    【讨论】:

    • 是的,每个动作都由 store 监听,并返回新状态,组件使用 connect from (react-redux) 连接到 store
    猜你喜欢
    • 1970-01-01
    • 2019-06-18
    • 2018-09-28
    • 2020-12-05
    • 2020-11-27
    • 2018-03-24
    • 1970-01-01
    • 1970-01-01
    • 2018-11-10
    相关资源
    最近更新 更多