liveBook · Manning

Submit handler

As explained in React Quickly, Second Edition

A submit handler is a function associated with a form that runs when the form is submitted.

A submit handler is the form-level function that processes submitted data. The browser invokes it when the user clicks a Submit button or presses Enter while focused in an input with a Submit button. section 9.2.4

Use the form’s submit handler because it:

  • Handles both mouse-based submission and Enter-key submission. section 9.2.4
  • Reads controlled-input values directly from React component state. section 9.2.4
  • Avoids mishandling keyboard submission, which can happen when logic is attached only to the button’s click handler. section 9.2.4

Submitting a controlled to-do form

A form component stores title, category, and date in state, then passes that data to its submit callback: `const onSubmit = (evt) => { handleAdd(data); evt.preventDefault(); }`.

How React Quickly, Second Edition covers it

How deep it goes
Explains invocation cases, controlled-state access, and the limitation of button-only click handlers.
Examples
Uses a controlled to-do form containing title, category, and date fields.
What it assumes
Assumes familiarity with controlled inputs and React component state.
What you can do after
Apply it via React by handling both button and Enter-key form submissions from component state.
How it connects
Connects forms with controlled inputs, component state, event handlers, and remote storage.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of React Quickly, Second Edition. The section links point to the parts of the book it draws on.