How to get selected value of a dropdown menu in ReactJS

Posted by Prem Tiwari | Updated on

Want to get selected value of a dropdown menu in ReactJS? The code in the render method represents the component at any given time. If you do something like this, the user won’t be able to make selections using the form control:

Controlled Components Use component state to reflect the user’s selections. This provides the most control, since any changes you make to state will be reflected in the component’s rendering:

Example:

Uncontrolled Components The other option is to not control the value and simply respond to onChange events. In this case you can use the defaultValue prop to set an initial value.


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers