I am creating a user session asking the server through an api if the session already exists and if it exists change the state to the session to true but I get this error "Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function. "
const [session, setSession] = useState();
Axios.defaults.withCredentials = true;
useEffect(() => {
Axios.get('http://localhost:3001/admin/api/session').then((res) => {
if (res.data.login === true){
setSession(true);
}
})
}, []);
if(session){
return <Route {...restoDePropiedades}>{children}</Route>
}else{
return <Redirect to="/admin-login"/>
}