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

Why would I never need to use subscribe in Redux?

如果在 React 中,我可以使用 connect 映射状态并分派到道具,我使用 connect 的组件将在 Redux 状态(以及道具)时自动呈现更改,为什么我需要使用 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.