【发布时间】:2020-06-07 05:08:17
【问题描述】:
我正在尝试在 redux 中创建某种初始化状态,因此当应用加载时,应用会从 redux(带有 thunk)获取一些数据并获取数据。
所以我只需要它一次,为此我将 [] 放在 useFffect 参数中, 但我收到以下错误:
Line 32:6: React Hook useEffect has missing dependencies: 'dispatch' and 'init'. Either include them or remove the dependency array react-hooks/exhaustive-deps
我无法将 useDispatch 插入到 useEffect 中
const { isReady } = useSelector<AppState, AppProps>((state: AppState) => {
return {
isReady: state.appStatus.isReady
};
});
const dispatch = useDispatch();
const init = initilizeAction();
useEffect(() => {
dispatch(init);
}, []);
【问题讨论】:
-
作为一种解决方法,您可以通过添加
// eslint-disable-next-line no-use-before-define来禁用它。
标签: reactjs redux use-effect