Course contentsShow
← React
Lesson 457 of 2,39613. Controlled ComponentsFree lesson

Controlled Select Dropdowns

Select elements use value on the <select> itself to control which option is selected, not on individual <option> tags.

What You'll Learn

You'll learn how to control <select> dropdowns in React by placing the value prop on the <select> element itself, not on the individual <option> tags.


The Key Difference from HTML

In regular HTML, you mark an option as selected by adding a selected attribute to that specific <option>. React takes a different approach: you control which option is selected by setting the value prop on the parent <select> element.

How Controlled Selects Work

Just like controlled text inputs, a controlled select dropdown follows the same pattern:

  1. Store the current selection in state
  2. Set the value prop on the <select> to that state
  3. Update state in an onChange handler

The value you set on <select> matches the value attribute of whichever <option> should appear selected.

Example

function FruitPicker() {
  const [fruit, setFruit] = useState('apple');

  return (
    <select value={fruit} onChange={(e) => setFruit(e.target.value)}>
      <option value="apple">Apple</option>
      <option value="banana">Banana</option>
      <option value="orange">Orange</option>
    </select>
  );
}

When fruit is 'apple', the Apple option shows as selected. When you change the dropdown, onChange fires, e.target.value contains the new selection, and you update state—which causes the dropdown to reflect the new choice.

Why This Matters

This centralized approach means your state is the single source of truth. You never have to hunt through <option> elements to find which one has selected—just look at your state variable.

Key Takeaway: Control <select> dropdowns by setting value on the <select> element (not on <option>), binding it to state, and updating state via onChange—exactly like controlled text inputs.