Redirection Not Working Because of Order of Executions of Functions
问题 I have a login page. If login is successful and token is present in local storage, I want to redirect to a private page /panel. I am calling all functions on the onSubmit() of my form. Here's what my code looks like: function LoginPage (){ const [state, setState] = useState({ email: '', password: '', }); const [submitted, setSubmitted] = useState(false); function ShowError(){ if (!localStorage.getItem('token')) { console.log('Login Not Successful'); } } function FormSubmitted(){ setSubmitted