React · Junior · Question 68 of 75

How do you set the selected option of a <select> in React?

<select value={country} onChange={(e) => setCountry(e.target.value)}>
  <option value="ua">Ukraine</option>
  <option value="pl">Poland</option>
</select>

Explanation

React warns if you use selected on options. multiple selects take an array as value.

Further reading

Problem with a question

React · Junior · question 68

Test yourself

Take the React · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz