Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
Submitting a form makes the browser navigate by default; handle onSubmit on the form and call event.preventDefault(), or use a form action.
A native form submission sends the data and navigates, which reloads a single-page app and loses state. Put the handler on the form's onSubmit, not only on the button's onClick, so pressing Enter in a field also works, and call event.preventDefault() before handling the data yourself. You can read values from state for controlled fields or from new FormData(event.currentTarget). In React 19 you can also pass a function to the form's action prop, which receives FormData and does not reload the page.