[英]getting "Cannot update a component (`BrowserRouter`) while rendering a different component" error on react project
here is the code snapshot of login which I getting the error in. I cannot solve it as a new react user please help.这是我收到错误的登录代码快照。作为新的 React 用户,我无法解决它,请帮忙。
The navigate
function should be called as an intentional side-effect, not in directly in the component body as an unintentional side-effect. navigate
function 应该作为有意的副作用调用,而不是直接在组件主体中作为无意的副作用调用。 Move that logic into an useEffect
hook.将该逻辑移至
useEffect
挂钩中。
Example:例子:
useEffect(() => {
if (user || userGoogle) {
navigate(from, { replace: true });
}
}, [navigate, user, userGoogle]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.