HTML vs React select dropdown
There are few differences between HTML and React select dropdown.
This is how we add select dropdown in HTML:
In the HTML dropdown above, we have “selected” attribute set for the first option so it will be selected automatically.
React does the same thing in a different way.
In React, we need to set “selected” attribute to the main select element.
How is that advantageous over the HTML?
Well, for HTML you need to type code to a specific location to auto select or even change the selection. With React the code stays at the same place so cleaner and nicer way to code.
Another advantage I can think of is that if you’re using a server side language, such as PHP, to add that selected attribute then you need to add the condition to each and every option. You can always come up with a login to reduce the code you write but still it makes a bit messier.
The way React changes the select dropdown using the root element control, the technique is called a controlled component.
React Dropdown Example
drop down elements examples form select