10 entries · 14-question quiz
Working with Forms & User Input
React ↔ Angular reference. React examples use React 19 + TypeScript. Angular examples use modern Angular (standalone components, signals, typed Reactive Forms with FormGroup/FormControl, @if/@for).
This topic covers forms handled with event handlers (onSubmit). React 19's <form action={fn}>, useActionState, useFormStatus and useOptimistic are covered in the next topic, Handling Forms via Form Actions.
Test yourself
14 questions
- 1Submitting a Form:
onSubmit,preventDefault, and Button TypesA form's
onSubmithandler runs when the form is submitted. Callingevent.preventDefault()stops the browser's default behavior: sending an HTTP request and reloading the page. - 2Controlled Inputs with One State Object
A controlled input gets its
valuefrom React state and updates that state inonChange. React state is the single source of truth for what the input shows. - 3Uncontrolled Inputs with Refs
An uncontrolled input keeps its own value in the DOM. React reads it only when needed, through a ref.
- 4Reading Values with
FormDataFormDatais a browser API (not React) that collects every named field of a<form>into key-value pairs. - 5Resetting Forms
Returning every field to its starting value after submission or on request.
- 6Controlled vs Uncontrolled: Choosing an Approach
Controlled inputs store values in React state; uncontrolled inputs leave them in the DOM and read them on submit.
- 7Built-in Browser Validation
HTML validation attributes let the browser check input and block submission, without JavaScript.
- 8Custom Validation: On Keystroke, On Blur, On Submit
Checking values in your own code and showing your own error messages, at a moment you choose.
- 9Reusable Inputs and a
useInputHookMoving repeated input markup into an
<Input>component and repeated state/validation logic into a custom hook. - 10Summary