bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/React/React Core
React•React Core

React Forms - Select

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind React Forms - Select?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

<___> <option value="Ford">Ford</option> <option value="Volvo" selected>Volvo</option> <option value="Fiat">Fiat</option> </select>
3Order

Put the learning moves in the order that makes the concept easiest to apply.

In React, the selected value is defined with a value attribute on the select tag:
In HTML, the selected value in the drop down list is defined with the selected attribute:
A drop down list, or a select box, in React is also a bit different from HTML.

Select

A drop down list, or a select box, in React is also a bit different from HTML.

In HTML, the selected value in the drop down list is defined with the selected attribute:

HTML

<select> <option value="Ford">Ford</option> <option value="Volvo" selected>Volvo</option> <option value="Fiat">Fiat</option> </select>

In React, the selected value is defined with a value attribute on the select tag:

Example

React uses the value attribute to control the select box:

function MyForm() {
 const [myCar, setMyCar] = useState("Volvo");
 const handleChange = (event) => {
 setMyCar(event.target.value)
 }
 return ( <form> <select value={myCar} onChange={handleChange}> <option value="Ford">Ford</option> <option value="Volvo">Volvo</option> <option value="Fiat">Fiat</option> </select> </form> )
}

By making these changes to the <select> element, React is able to handle it as any other input element.

Previous

React Forms - Textarea

Next

React Forms - Multiple Input Fields