React redux - “超过最大更新深度”错误

dec*_*bal 5 reactjs react-router react-redux

当我想登录我的应用程序时,在输入正确的详细信息并按“登录”按钮后,出现此错误:

在此处输入图片说明

如代码所示,URL 更改为“仪表板”,但我看不到页面内容,但出现上述错误。

在控制台中,我可以看到来自 Header 组件(它是仪表板的一部分)的代码被多次访问(我认为这是导致问题的原因):

在此处输入图片说明

如果我刷新页面,一切正常。另外,如果我注销并返回登录页面,我可以毫无错误地登录。但是,如果我刷新页面并尝试登录,则会返回错误。

这是代码:

标题组件:

const Header = withRouter(({ history }) => {

const values = useSelector((state) => ({...state.sharedReducer}));
console.log('***  VALUES: ', values);
const dispatch = useDispatch();

const handleMenuClick = () => dispatch(menuClickAction());
const handleLinkClick = () => dispatch(closeMenuAction());
................
Run Code Online (Sandbox Code Playgroud)

登录组件:

  //  Runs only once on init
  useEffect(() => {
    if(isAuth) {
      props.history.push("dashboard"); //  Redirect to 'dashboard'
    }
  });

  useEffect(() => {
    //  Clear the form
    dispatch(clearFormDataAction());
  }, [dispatch]);

  useEffect(() => {
    if(!values.emailEmptyError && !values.passwordEmptyError && values.email.length && values.password.length && !values.isFormValid) {
      dispatch(enableSubmitButtonAction());
        }
  }, [values, dispatch]);

  const handleSubmitForm = (e) => {
    e.preventDefault();
    handleLoading(true);

    const loginDetails = {
      email: values.email,
      password: values.password
    };

    AuthService.login(loginDetails)
      .then(response => {
        if(response) {
          LocalStorageService.setItem('currentUser', response.data.user);
          props.history.push("dashboard"); //  Redirect to 'dashboard'
        }
      })
      .catch((error) => {
        handleSubmitError(i18n.t("ERRORS.LOGIN_WRONG_DETAILS"));
        console.log('error: ', error);
      });
   }
Run Code Online (Sandbox Code Playgroud)

有人可以请教有什么问题吗?谢谢!