相关疑难解决方法(0)

React Hook useEffect 缺少依赖项:'dispatch'

这是我第一次使用 react js,我试图在离开此视图时删除警报,因为我不想在另一个视图上显示它,但如果没有错误,我想保持成功警报以显示当我要重定向到另一个视图时

但我在谷歌浏览器上穿上了这件衣服 Line 97:6: React Hook useEffect has a missing dependency: 'dispatch'. Either include it or remove the dependency array react-hooks/exhaustive-deps

如果我确实包括调度,我会得到无限循环

const [state, dispatch] = useUserStore();
useEffect(() => {
    let token = params.params.token;
    checktoken(token, dispatch);
  }, [params.params.token]);

  useEffect(() => {
    return () => {
      if (state.alert.msg === "Error") {
        dispatch({
          type: REMOVE_ALERT
        });
      }
    };
  }, [state.alert.msg]);

//response from the api
if (!token_valide || token_valide_message === "done") {
      return <Redirect to="/login" />;
    }
Run Code Online (Sandbox Code Playgroud)

这是 useUserStore

  const globalReducers …
Run Code Online (Sandbox Code Playgroud)

reactjs react-hooks

28
推荐指数
1
解决办法
3万
查看次数

标签 统计

react-hooks ×1

reactjs ×1