initially, redux state of isloggedin is false,which then rendered login page. then after page load, I have updated the state to loggedIn, but privateRoute is not redirecting
export default function ProtectedRoute({ children }: any) {
const isLoggedIn = useSelector((state: State) => state.user.isLoggedIn);
useEffect(()=>{
console.log("isLoggedIn",isLoggedIn,children)
},[isLoggedIn])
return !isLoggedIn ? <Navigate to="/login"/> : children;
}
I also tried putting isloggedin inside of dependency array so as to re render it on state change, I think it registered the new routes but did not update the already updated page of login. i want to write the redirect logic in this component only