定期在 React-Redux Connect 停止调试
debugging stopped at React-Redux Connect periodically
我使用 React-Redux 有一段时间了,但是在调试组件和存储之间交互的“连接”时我总是有一个问题,例如
ln export default connect((state) => {
112 return {
113 isUserAdmin: isUserAdmin(state)
114 };
115 })(MainPage);
isUserAdmin(state) {
222 // perform a heavy task...
}
如果我在第 113 行 处放置一个断点,即使我没有对我的组件进行任何更改,我发现它也会每 1 秒定期触发一次因为我的函数 isUserAdmin(state) 一直在执行,一直在执行,从未停止过,难道是 react-redux 设计的东西吗?
我还发现在我的调用堆栈中有一些 订阅 触发了连接(mapStateToProps),这是否意味着在幕后 react-redux 正在使用某种 订阅或承诺执行轮询以维护状态?
顺便说一句,如果我的 isUserAdmin 正在做繁重的工作,或者我通过执行额外的方法传递额外的 mapStateToProps,那会不会对我的应用程序性能产生很大影响,因为看起来 运行无限幕后?
even if I didn't make any change in my component, I found that it's being triggered periodically every 1 seconds.
- 它与您在组件中所做的更改(本地组件状态更新)无关(除非您通过调度
actions
进行任何存储更新)。它只监听 store
更新。
- 第一次在应用程序加载时以默认
redux
store
状态触发。后续触发器取决于您通过调度 actions
. 在 application/components 中进行的商店更新
does it mean behind the scene react-redux is using some kind of subscription or promise to perform a polling to maintain the state?
- 是的。它订阅商店更新。
事情解释得很好here.
if my isUserAdmin is doing a heavy job or I pass additional mapStateToProps through executing additional methods, would that impact a lot in my application performance.
- React 将作为 救世主 来到这里。如果 state/reference 未更改,UI/Component 将不会重新呈现。
我建议您将 isUserAdmin
逻辑移动到 React 组件,并使用 useMemo()
挂钩来优化密集计算的性能。为了你的 reference.
我使用 React-Redux 有一段时间了,但是在调试组件和存储之间交互的“连接”时我总是有一个问题,例如
ln export default connect((state) => {
112 return {
113 isUserAdmin: isUserAdmin(state)
114 };
115 })(MainPage);
isUserAdmin(state) {
222 // perform a heavy task...
}
如果我在第 113 行 处放置一个断点,即使我没有对我的组件进行任何更改,我发现它也会每 1 秒定期触发一次因为我的函数 isUserAdmin(state) 一直在执行,一直在执行,从未停止过,难道是 react-redux 设计的东西吗?
我还发现在我的调用堆栈中有一些 订阅 触发了连接(mapStateToProps),这是否意味着在幕后 react-redux 正在使用某种 订阅或承诺执行轮询以维护状态?
顺便说一句,如果我的 isUserAdmin 正在做繁重的工作,或者我通过执行额外的方法传递额外的 mapStateToProps,那会不会对我的应用程序性能产生很大影响,因为看起来 运行无限幕后?
even if I didn't make any change in my component, I found that it's being triggered periodically every 1 seconds.
- 它与您在组件中所做的更改(本地组件状态更新)无关(除非您通过调度
actions
进行任何存储更新)。它只监听store
更新。 - 第一次在应用程序加载时以默认
redux
store
状态触发。后续触发器取决于您通过调度actions
. 在 application/components 中进行的商店更新
does it mean behind the scene react-redux is using some kind of subscription or promise to perform a polling to maintain the state?
- 是的。它订阅商店更新。 事情解释得很好here.
if my isUserAdmin is doing a heavy job or I pass additional mapStateToProps through executing additional methods, would that impact a lot in my application performance.
- React 将作为 救世主 来到这里。如果 state/reference 未更改,UI/Component 将不会重新呈现。
我建议您将 isUserAdmin
逻辑移动到 React 组件,并使用 useMemo()
挂钩来优化密集计算的性能。为了你的 reference.