Select Dropdown: value on the select Element
You'll learn how to control a <select> dropdown by placing the value prop on the <select> element itself, not on individual <option> tags.
The Pattern with Select Elements
Unlike HTML's default behavior where you mark an option as selected, React controlled components handle dropdowns differently. You set the value prop on the <select> element, and React automatically highlights the matching <option>.
const [fruit, setFruit] = useState('apple');
<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>
Reading the Selected Value
Just like text inputs, you read the selected value from e.target.value in your onChange handler. This value matches the value attribute of whichever <option> the user picked.
Why value Goes on select
Think of the <select> as the container that "knows" which option is active. The individual <option> elements simply provide the available choices. By putting value on <select>, you're telling React "this dropdown's current selection is controlled by state."
function FruitPicker() {
const [fruit, setFruit] = useState('banana');
return (
<div>
<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>
<p>You selected: {fruit}</p>
</div>
);
}
React matches the value prop on <select> with the value attributes on <option> elements to determine which one appears selected.
Key Takeaway: Control a select dropdown by setting value on the <select> element and reading e.target.value from its onChange handler—the same pattern as text inputs, just on the container element instead of a self-closing tag.