Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 5.2 — Checkboxes, Radio Buttons and Selects
React · Example 3 of 3

A multiple select keeps an array

value is an array, and the handler builds a new array from selectedOptions. Hindi starts selected because it is in the initial array.

Checkboxes and radios are controlled with checked (a boolean), selects with value (a string, or an array for multiple), and every value that comes out of a field, even a number field, is a string you convert yourself.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Build a controlled "Remember me" checkbox and a paragraph that says You will stay signed in or You will be signed out.

02

Build a radio group for delivery speed (standard, express) that shows the price: ₹40 or ₹120.

03

Build a select of three themes (light, dark, sepia) that sets a className on a preview div.

Explain it without notes

01

How do you control a checkbox in React, and why is e.target.value the wrong thing to read?

02

How do you build a radio group in React? What does the name attribute do?

03

How do you control a <select multiple> and read its chosen values?

04

Why should a number field's state usually be a string?

A multiple select keeps an array

Preview

Press Run to see the page.

Console

Nothing logged yet.