I have a drop down list for all the countries in the world with their abbreviated code. Now i want to call a useState to set it and use it to insert it to my DB.
How can i do that?
here is my code:
example of the list:
export const countryList =[
{name: 'Afghanistan', code: 'AF'},
{name: 'Åland Islands', code: 'AX'},
{name: 'Albania', code: 'AL'},
{name: 'Algeria', code: 'DZ'},
{name: 'American Samoa', code: 'AS'},
const [collcountry,setCollCountry] = useState("");//this is being set
const [collcountrycode,setCollCountryCode] = useState("");// But how can i set the
//country code from the title property?
<Form.Select aria-label="Select Country" onChange={(e)=> { setCollCountry(e.target.value) }} >
<option></option>
{ countryList.map((e, key) => (
<option key={key} title={e.code} value={e.name}>{e.name}</option>))
}
</Form.Select>
e.codeinstead ofe.target.value?