简体   繁体   English

组件在 componentWillUpdate 或 componentDidUpdate 中重复调用 setState。 React 限制了编号。 嵌套更新以防止无限循环

[英]component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the no. of nested updates to prevent infinite loops

I am getting this error:"Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops."我收到此错误:“超出最大更新深度。当组件在 componentWillUpdate 或 componentDidUpdate 中重复调用 setState 时,可能会发生这种情况。React 限制嵌套更新的数量以防止无限循环。”

When history.push("/") in demoPortalPage is called, sometimes it goes in infinite loop and set path infinite times.调用demoPortalPage 中的history.push("/")时,有时会无限循环并无限次设置路径。

Screenshort of Errors: screenshort of error错误截图:错误截图

DemoPortalPage.jsx演示门户页面.jsx

useEffect(() => {
    const authenticateDemoUser = async () => {
        const authData = {
            email: 'demo@gmail.com',
            password: '1234',
        };

        const checkUserAuth = await postRequest("authenticate", authData);

        if (checkUserAuth?.status >= 200 && checkUserAuth?.status < 300) {
            // sign in success action call
                await signInSuccess(checkUserAuth.data);
                await getAndSaveUserName();
                await setIsUserVerified(true);
                // localStorage.setItem('is_demo', "true")
                history.push("/");
            
        } else {
             await setIsUserVerified(false);
             history.push("/");
        }
    }
    authenticateDemoUser()

}, [])

App.jsx应用程序.jsx

 ....   
    <Route exact path={"/login"} render={() => (isUserVerified ? <Redirect to="/" /> : <LoginPage/>)} />
                               
    <Route exact path={"/demo-login"} component={DemoPortalPage} />
 ....

Please help me for solve this error请帮我解决这个错误

It is solved and I want to give you clarify for this thing on my case perspective... In my case it was happening because of asynchronous sequence.,.它已解决,我想从我的案例角度为您澄清这件事......在我的案例中,它是由于异步序列而发生的...... Before it saves data in state. Page redirects to another page and next page don't get that data,.!在将数据保存在 state 之前。页面重定向到另一个页面,下一页没有获取该数据,。! As per my routing code, If page don't have that specific data it checks again and again in loop and that's why infinite loop error occurs.根据我的路由代码,如果页面没有特定数据,它会在循环中一次又一次地检查,这就是无限循环错误发生的原因。

Thank you.谢谢你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 componentWillUpdate 或 componentDidUpdate 中重复调用 setState。 React 限制嵌套更新的数量以防止无限循环 - repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops 如何修复“超出最大更新深度。在 componentWillUpdate 或 componentDidUpdate 中调用 setState。” 反应错误? - How to fix “Maximum update depth exceeded.calls setState inside componentWillUpdate or componentDidUpdate.” error in react? 在componentDidUpdate中调用函数。 错误:React限制了嵌套更新的数量 - Calling functions in componentDidUpdate. Error: React limits the number of nested updates 超出最大更新深度。 当组件在componentWillUpdate或componentDidUpdate中重复调用setState时,可能会发生这种情况 - Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate 不变违反:最大更新深度..当组件重复调用componentWillUpdate或componentDidUpdate内部的setState时 - Invariant Violation: Maximum update depth..when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate 未捕获的错误:当组件在 componentWillUpdate 或 componentDidUpdate 中重复调用 setState 时,可能会发生这种情况 - Uncaught Error: This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate 错误:超过最大更新深度。 当组件在 componentWillUpdate 或 componentDidUpdate 中重复调用 setState 时,可能会发生这种情况 - Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate 错误:超出最大更新深度。 当组件在 componentWillUpdate 或 componentDidUpdate 中重复调用 setState 时,可能会发生这种情况 - Error: Max update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate 在componentWillUpdate或componentDidUpdate中反复调用setState? - Repeatedly calling setState inside componentWillUpdate or componentDidUpdate? ReactJs:错误:超出最大更新深度。 React 限制嵌套更新的数量以防止无限循环 - ReactJs :Error: Maximum update depth exceeded. React limits the number of nested updates to prevent infinite loops
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM