JavaScript / Learning to Code / React.js

react logo select box

Maybe it’s just me, but the first time I built a select box in react, I was a little confused how it would work. When an option is selected, is it an onSelect event? How is the value entered into the state? Here is what I learned.

I was over thinking it. It turns out a select is pretty much handled the same way as any other react input. The <select> receives an onChange handler that can set the new state with the target value of the selected option. The code should make more sense than my words, so let’s just skip to that.

React Select Box

See the Pen React Select Box by Brandon (@blehr) on CodePen.

 


Brandon Lehr

I'm Brandon Lehr, a web developer, machinist, and sometimes mechanic ( when the truck breaks down ). I guess you could say that I enjoy solving problems and building things.

Bootstrap Tabs, React Router, and the active class Software Solves Problems