Concept
Handle submit on the form, not on the button, so Enter works too. Prevent the browser's default navigation, read the values, and show the pending and result states.
The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.
A few lines that show Form submission doing its job.
function Login() {
const [pending, setPending] = useState(false);
async function onSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
const data = new FormData(event.currentTarget);
setPending(true);
try {
await login(String(data.get("email")), String(data.get("password")));
} finally {
setPending(false);
}
}
return <form onSubmit={onSubmit}>...<button disabled={pending}>Sign in</button></form>;
}Forgetting event.preventDefault(). The browser submits the form the old-fashioned way and reloads the page, and the request you started is thrown away.
Your roadmap puts these before Form submission, unless you already know them.
Once a session shows you understand Form submission, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.
Topics that build on Form submission.