【发布时间】:2021-04-15 08:10:19
【问题描述】:
我有一个自定义钩子:useNavigation()。如果需要,它会返回目标路由以重定向用户。
在钩子里面我使用redux store(只读取值):
{ prop1, prop2 } = useTypedSelector(state => state.data);
useTypedSelector 代码在哪里:
const useTypedSelector: TypedUseSelectorHook<RootState> = useSelector;
TypedUseSelectorHook 和 useSelector hooks 来自 react-redux,而 RootState 是我的 root reducer 的一种。
我有以下实际结果: 如果 redux store 发生变化,那么这个变化会触发意外的 useNavigation 钩子调用。
但我的预期结果是: useNavigation hook 使用 redux store 读取值,但它们不会触发 useNavigation hook on change。
如何防止 redux 状态变化时产生额外的钩子调用?
【问题讨论】:
标签: reactjs typescript redux react-redux react-hooks