npm i react-native-option-dropdown
MacOS needs this extra step (called from the MacOS directory)
pod install
Import Dropdown from react-native-option-dropdown'
:
import Dropdown from 'react-native-option-dropdown';
Create state which will be used by the Dropdown
:
const [selectedItem, setSelectedItem] = useState(null);
Add Dropdown
like this:
import { StyleSheet, Text, View } from 'react-native'
import React, {useState} from 'react';
import Dropdown from 'react-native-option-dropdown'
const App = () => {
const [selectedItem, setSelectedItem] = useState(null);
let data = [
{id: 1, name: 'All'},
{id: 2, name: 'Today'},
{id: 3, name: 'Yesterday'},
{id: 4, name: 'Current Week'},
];
const onSelect = item=>{
setSelectedItem(item);
alert(item.name)
}
return (
<View style={{marginTop:'10%'}}>
<Dropdown
data={data}
onSelect={onSelect}
value={selectedItem}
/>
</View>
)
}
export default App