I am using react-native-select-dropdown and set data array statically but don't know how to set data array dynamically from apis with id
Code :
const countries = ["Egypt", "Canada", "Australia", "Ireland"]
<SelectDropdown
data={countries}
// defaultValueByIndex={1}
// defaultValue={'Egypt'}
onSelect={(selectedItem, index) => {
console.log(selectedItem, index);
}}
defaultButtonText={"Select"}
buttonTextAfterSelection={(selectedItem, index) => {
return selectedItem;
}}
rowTextForSelection={(item, index) => {
return item;
}}
/>
how to set countries array list dynamically and i need both title and id of selected item, the fetching data from api are:
const countries = [
{namd: 'Egypt', id: 1},
{namd: 'Canada', id: 2},
{namd: 'Australia', id: 3},
{namd: 'Ireland', id: 4},
];
useStatefor functional components, check this link:https://reactjs.org/docs/hooks-state.html