Raman Choudhary Raman Choudhary - 17 days ago 7
HTML Question

Alternative for onChange event for <select> tag in ReactJS?

I'm creating a Component that has multiple

<select>
tags. Based on the selected option it fetches options for the next tag. I'm using onChange event. The problem I'm facing is if there's only 1 option in then onChange is never triggered.

Is there any event in ReactJS, like
onSelect
that I can use to achieve this or, any better method?

Answer

Could you not make the first option a disabled placeholder as follows:

<option disabled selected value> -- select an option -- </option>

That way the the user would have to trigger a fetch.

If you require a default state you can handle this outside of the select box.