Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have a placeholder for react native picker

Tags:

react-native

Is there a way to have a placeholder for the react native picker that is shown before the user clicks on it. The idea would be to have a picker that says "Nationality" and once you click and choose your country it renders the country. I want to do this without having "Nationality" as an available option in the picker.

like image 427
Tiagojdferreira Avatar asked Sep 07 '25 17:09

Tiagojdferreira


2 Answers

Place a first children as <Picker.Item value='' label='Placeholder text...' />

like image 190
sospedra Avatar answered Sep 10 '25 07:09

sospedra


I'm not clear this is the right way.

<Picker selectedValue={locals.value}
onValueChange={value => {
    if (value != "0")
        this.pickerValueChange(value)

    // so it won't care if header is selected...
}}>
    <Picker.Item label="Select Type" value="0" />
    <Picker.Item label="Diesel" value="Diesel" />
    <Picker.Item label="Gas" value="Gas" />
    <Picker.Item label="Electricity" value="Electricity" /> 
</Picker>

pickerValueChange function:

pickerValueChange = val => {
    // state change or whatever you want to perform on picker update
}
like image 39
Amal K.R Avatar answered Sep 10 '25 07:09

Amal K.R