Building a React Select Box Component

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

 


I'm Brandon Lehr, your friendly, neighborhood developer

✱ May or may not be friendly, most likely not your neighbor