You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While configuring a React web app, I wrote a component that checks a status value and sends a user who is not logged in to the login page.
However, when I call toast.error inside the useEffect while navigating to it, I get the error below.
Warning: Cannot update a component (`Ie`) while rendering a different component (`ProtectedRouter`). To locate the bad setState() call inside `ProtectedRouter`, follow the stack trace as described in https://reactjs.org/link/setstate-in-render
This is my code.
importtoastfrom"react-hot-toast";import{Navigate,Outlet}from"react-router-dom";import{ROUTES}from"../constants";import{useStore}from"../store";exportdefaultfunctionProtectedRouter(){constuser=useStore((state)=>state.user);if(!user){toast.error("로그인이 필요한 페이지입니다.");return<Navigateto={ROUTES.SIGN_IN}replace/>;}return<Outlet/>;}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
While configuring a React web app, I wrote a component that checks a status value and sends a user who is not logged in to the login page.
However, when I call
toast.error
inside the useEffect while navigating to it, I get the error below.This is my code.
and router
Thank you for all your help.
Beta Was this translation helpful? Give feedback.
All reactions