I have a probleme with my state, i’m trying to get an item from local storage and set it into my state, but when i log my state it is empty and I ensure that local storage item has a value
this is what im trying, but when I log token it is empty, but the property call _token it has the value
export const ProtectedRoute: React.FC<ProtectedRouteProps> = ({children})=>{
const [token, setToken] = useState<string>("");
useEffect(()=>{
const _token:string | null = localStorage.getItem("token");
if(_token){
setToken(_token);
console.log("token ", token);
}
},[]);
return token ? children : <Navigate to={"/sign-in"}/>
}