React TutorialLesson 32Free preview
React Select
This lesson is part of React · All levels
Summary
Dropdown select on React is also controlled by the value attribute on the select tag, rather than the selected attribute on each option. The selected value is stored in the state through onChange so that it is always synchronized with the display. With this pattern, both the default and dynamic options are easily configured.
Key points
- Value is placed on the select tag, not on the option
- OnChange saves user preferences to state
- For the initial option, set the default value to state
- Options can be generated from arrays of data using maps.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.