Redux #subscribe 与 #mapStateToProps
Redux #subscribe vs. #mapStateToProps
在 store.subscribe(render)
这样的代码中使用 subscribe
的目的是什么?使用 mapStateToProps
和 connect
不会导致连接的组件在每次商店状态更改时重新呈现吗?
显示 store.subscribe(render)
的示例使用小代码片段向您展示了将 redux 与 React 挂钩的基本方法。
store.subscribe
来自 redux
包。
connect
来自 react-redux
包,不是 redux 本身的一部分。
react-redux
包使用 store.subscribe
将自身挂接到 redux 调度周期。然后,您可以使用 connect
组件增强器访问 redux 存储。
第三方库(或中间件)可以通过 store.subscribe
连接到商店生命周期。
引用 Redux.js 页面:
Technically you could write the container components by hand using store.subscribe(). We don't advise you to do this because React Redux makes many performance optimizations that are hard to do by hand. For this reason, rather than write container components, we will generate them using the connect() function provided by React Redux,
如果你已经在使用react with redux,你不妨使用他们的包,因为它已经被优化过了。
同时引用了之前的回答:
在 store.subscribe(render)
这样的代码中使用 subscribe
的目的是什么?使用 mapStateToProps
和 connect
不会导致连接的组件在每次商店状态更改时重新呈现吗?
显示 store.subscribe(render)
的示例使用小代码片段向您展示了将 redux 与 React 挂钩的基本方法。
store.subscribe
来自 redux
包。
connect
来自 react-redux
包,不是 redux 本身的一部分。
react-redux
包使用 store.subscribe
将自身挂接到 redux 调度周期。然后,您可以使用 connect
组件增强器访问 redux 存储。
第三方库(或中间件)可以通过 store.subscribe
连接到商店生命周期。
引用 Redux.js 页面:
Technically you could write the container components by hand using store.subscribe(). We don't advise you to do this because React Redux makes many performance optimizations that are hard to do by hand. For this reason, rather than write container components, we will generate them using the connect() function provided by React Redux,
如果你已经在使用react with redux,你不妨使用他们的包,因为它已经被优化过了。
同时引用了之前的回答: