I want to float the main page when the token exists. but it isn't movement my code.. plz help me TT
const App = () => {
const [token, setToken] = useState(null);
useEffect(()=> {
const hash = getTokenFromResponse();
window.location.hash = "";
const token = hash.access_token;
console.log('token', token);
const userManager = {
token : token,
};
console.log(userManager);
}, []);
return(
<div className="login">
{!token && <Login/>}
{token && <Main/>}
</div>
)
}
You forgot to update the state
useEffect(()=> {
// ...
setToken(token)
}, []);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.