I am using Formik and react-native-picker-select, I can reset text and number fields after submission but can not able to reset picker-select. How can I achieve it?
The reseted value for react-native-picker-select is null.
So you need to create a state that stores the current value of the picker and when you want to reset it, set it to null.
The secret here is set the value={state variable} parameter, so that the picker updates every time that the state is also updated. The state variable is updated with onValueChange.
const Component = () => {
const [pickerValue, setPickerValue] = useState(null);
return (
<>
<RNPickerSelect
onValueChange={v => setPickerValue(v)}
value={pickerValue}
items={[
{label: 'Football', value: 'football'},
{label: 'Baseball', value: 'baseball'},
{label: 'Hockey', value: 'hockey'},
]}
/>
<TouchableOpacity onPress={() => setPickerValue(null)}>
<Text>Submit</Text>
</TouchableOpacity>
</>
);
};