I use react-native-element-dropdown package in my app.
I want to add dynamic data in the component. But first, I would like to add an empty dropdown option value like:
{label: '-- Please Select --', value: ""}
const dropdownData = () => {
if(userList){
return userList?.filter(user => user.id != null).map((user, index)=> {
return {label: user.username, value: user.id}
})
}
}
The dropdownData
is called in component’s data property:
<Dropdown data={ dropdownData() } />
How can I add the empty value before the userList
map?
2
Answers
Append your hard-coded option to the array before returning:
You can do the same in the JSX:
try this: