gpt4 book ai didi

reactjs - 就 Redux 而言, View 渲染是触发 store 设置初始状态的原因吗?还是商店最初是先成立的?

转载 作者:行者123 更新时间:2023-12-04 08:40:36 27 4
gpt4 key购买 nike

我阅读了以下文档。

Redux Application Data Flow

Earlier, we talked about "one-way dataflow", which describes this sequence of steps to update the app:

  • State describes the condition of the app at a specific point in time
  • The UI is rendered based on that state
  • When something happens (such asa user clicking a button), the state is updated based on what occurred
  • The UI re-renders based on the new state For Redux specifically, wecan break these steps into more detail:

Initial setup:

  • A Redux store is created using a root reducer function
  • The store calls the root reducer once, and saves the return value asits initial state
  • When the UI is first rendered, UI components accessthe current state of the Redux store, and use that data to decide whatto render. They also subscribe to any future store updates so they canknow if the state has changed.

但是,这是否意味着在设置应用程序时,首先创建 Redux 存储,然后是查看存储的 View 以呈现 UI 组件?或者 Redux 存储真的只有在 View 需要呈现 UI 组件之后才设置?
那么,是这个吗?

Initial store set up -> View render -> Access store state -> Display UI


或者是这个?

View render -> Initial store set up -> Access store state -> Display UI

最佳答案

这将是:

Initial store set up -> Access store state -> View render -> Display UI


查看此代码:
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById("root")
);
  • (初始商店设置):store首先通过 createStore() 创建.在这里,创建了整个应用程序状态树。
  • (访问商店状态):通过 mapStateToProps() 将其映射为 Prop . React 需要知道该组件正确渲染所需的状态和 Prop 。
  • (View Render): 然后 React 会调用组件的 render()或功能组件的返回。
  • (显示 UI):然后将此输出安装在 DOM 中或更新状态更改(循环回到第 2 步)。

  • React's lifecycle recap作为引用。

    关于reactjs - 就 Redux 而言, View 渲染是触发 store 设置初始状态的原因吗?还是商店最初是先成立的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64585572/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com