gpt4 book ai didi

reactjs - 为什么我永远不需要在 Redux 中使用订阅?

转载 作者:行者123 更新时间:2023-12-03 13:25:57 27 4
gpt4 key购买 nike

如果在 React 中,我可以使用 connect 来映射状态并调度到 props,并且我使用 connect 的组件将在 Redux 状态 (因此 props) 发生变化,为什么我需要使用 subscribe

最佳答案

您正在谈论 Redux 和 Redux-React(它提供 connect 函数,专门用于 React 组件)。 Take a look at how Redux-React is implemented .

connect 只是对 subscribe 的 React 特定抽象。

如果您不使用 React 会发生什么?完全可以将 Redux 与其他框架甚至简单的 Javascript 应用程序一起使用。在这些情况下,需要有一个较低级别的机制来订阅状态更改。

他们还更新了文档以说明有关 subscribe 的内容

It is a low-level API. Most likely, instead of using it directly, you'll use React (or other) bindings. If you commonly use the callback as a hook to react to state changes, you might want to write a custom observeStore utility. The Store is also an Observable, so you can subscribe to changes with libraries like RxJS.

关于reactjs - 为什么我永远不需要在 Redux 中使用订阅?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35110993/

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