I have 3 nested selects: Country -> State -> City.
But when I change the Country, the State is updated but not the City.
The code: https://codesandbox.io/s/change-a-selects-options-based-on-another-dropdown-using-react-forked-hjfr2m?file=/src/App.js
2
That is correct. When you change country, onChange in State
<select onChange={handleChange}>{options}</select>
gets triggered. So it changes the value. Since you are not triggering State, City is untouched
You can add a useEffect in your Category component :
Category
useEffect(()=> { if (category) setSelected(category.options[0]) }, [category])
Click here to cancel reply.
2
Answers
That is correct. When you change country, onChange in State
gets triggered. So it changes the value. Since you are not triggering State, City is untouched
You can add a useEffect in your
Category
component :