Displayed value not changing in react-native-picker-select after select

947 views Asked by At

The value isn't updating when I select an option in RNPickerSelect.

<RNPickerSelect
    key={comp}
    fixAndroidTouchableBug={true}
    useNativeAndroidPickerStyle={true}
    onValueChange={(value) => {
        setComp(value);
    }}
    style={pickerStyle}
    placeholder={{
       label: 'Select item',
       value: comp,
    }}
    items={companies}
    doneText="Valider"
/>
1

There are 1 answers

0
David Leavitt On

https://github.com/lawnstarter/react-native-picker-select

You need to add a 'value' property. Adding the value property helps the picker to find and show the selected value. Something like this:

<RNPickerSelect
    key={comp}
    fixAndroidTouchableBug={true}
    useNativeAndroidPickerStyle={true}
    onValueChange={(value) => {
        setComp(value);
    }}
    style={pickerStyle}
    placeholder={{
       label: 'Select item',
       value: null,
    }}
    items={companies}
    doneText="Valider"
    value={comp}
/>

Also, your placeholder value should be null, not equal to the state value.