Reputation: 133
does anyone have an example of a default value used in the library react-native-dropdown-picker used hooks e function, or another libre that makes this msm function simpler.
export default function OrphanageData() {
const [date, setDate] = useState(new Date())
const [value, setValue] = useState();
const [items, setItems] = useState([{}]);
let controller;
return (
<>
<StatusBar backgroundColor="#15c3d6"/>
<ScrollView style={styles.container} contentContainerStyle={{ padding: 24 }}>
<Text style={styles.title}>Compras</Text>
<Text style={styles.label}> ID - Brinco</Text>
<TextInput
style={styles.input}
/>
<DropDownPicker
items={items}
controller={instance => controller = instance}
onChangeList={(items, callback) => {
new Promise((resolve, reject) => resolve(setItems(items)))
.then(() => callback())
.catch(() => {});
}}
defaultValue={value}
onChangeItem={item => setValue(item.value)}
/>
<RectButton style={styles.nextButton} onPress={() => {}}>
<Text style={styles.nextButtonText}>Cadastrar</Text>
</RectButton>
</ScrollView>
</>
) }
Upvotes: 5
Views: 10416
Reputation: 6967
This might help (Using Hooks)
export default function OrphanageData() {
const [value, setValue] = useState('usa');
const [items, setItems] = useState([
{label: 'USA', value: 'usa'},
{label: 'UK', value: 'uk'},
{label: 'France', value: 'france'},
]);
return(
<DropDownPicker
items={items}
defaultValue={value}
onChangeItem={item => setValue(item.value)}
.....
/>
);
}
Upvotes: 2