I have a set of data by which I want to update my UI select option but I don't have any idea how I can do that
JSON data
[
{
country: 'India',
cities: [
{
city_name: 'New delhi',
},
{
city_name: 'mumbai',
},
],
},
{
country: 'England',
cities: [
{
city_name: 'London',
},
{
city_name: 'manchester',
},
],
},
{
country: 'Portugal',
cities: [
{
city_name: 'Lisbon',
},
],
},
];
What I've tried is :
<select
name="country">
{data.map((li, index) => (
<option
key={index}
value={li.country}
onchange={() => onchange_device(li.country)}>
{li.country}
</option>
))}
</select>
<select
name="city">
<option
value="city val
>
here I want to show city
</option>
))}
</select>
I am trying to do on-change, but first of all I want to show first option as selected and there sub cities should also be selected next, I don't have any idea how to do this