liveBook · Manning

Web form

As explained in React Quickly, Second Edition

An HTML form is a group of web controls and submission behavior defined by the HTML form element.

A web form groups controls that collect user input. Text fields, check boxes, drop-downs, and file inputs let people enter information for tasks such as logging in or placing an order. section 9.0

<form>
 <button>Click me</button>
</form>

A button inside a form submits it even when the form has no inputs. section 8.4.1

Submission is a browser action, not just a button click. By default, the form sends its values to its target URL and reloads the page. If no target URL is specified, the target is the current page. This still happens when there are no inputs. section 8.4.1

In React, choose who keeps track of each input’s current value:

  • Controlled inputs keep their values in component state. This keeps form logic and data flow inside React. section 9.0
  • Uncontrolled inputs leave their values with the browser; React reads them when needed. They use built-in browser handling but give the application less control over later changes. section 9.0

A change handler can read a checkbox through `evt.target.checked`. In a submit handler, a named control can be reached through the form’s `elements` property—for example, `evt.target.elements.email`. An uncontrolled input can receive an initial value, though React does not update that value afterward. section 9.5

A form for adding a timer

Put the timer inputs and a button inside a `<form>`. The button serves as its submit button without extra markup. The form component can keep its own input state and call a callback when submitted, leaving the timer list to handle what happens next. Give inputs appropriate labels. section 12.1.1 section 12.6

<form class="timer timer-new">
 <ul class="parts">
   <!-- input -->
   <li class="colon">:</li>
   <!-- input -->
 </ul>
 <!-- button -->
</form>

The timer form groups its inputs and submit button as one UI element. section 12.1.1

How React Quickly, Second Edition covers it

How deep it goes
Explains browser submission defaults and controlled versus uncontrolled state, then shows form structure and event-based access to controls.
Examples
Uses a bare button-in-form example, a timer-creation form, and a task-step form exercise.
What it assumes
Starts with plain HTML form behavior before introducing React choices for managing input values.
What you can do after
Build it from scratch: group labeled inputs and a submit button, then manage form state and pass submitted data through a callback.
How it connects
Connects forms to browser events, component state, controlled inputs, uncontrolled inputs, and semantic HTML.

Also explained in

Compare how 12 books explain web form →

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.