-
Notifications
You must be signed in to change notification settings - Fork 500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not able to select Number values since @react-native-picker/picker upgrade to 2.6.1 #530
Comments
We are having the same issue, also objects as values don't seem to work. Only strings are working |
Same here, any update? |
I'm having the same issue on react-native 73.2. |
Has anyone found a solution? |
Any Solutions please |
use strings only with picker and convert them to numbers when needed... |
I experienced the same issue ! |
Seems issue originates from here: react-native-picker/picker#538 |
Temporary solution: create a wrapper component that converts a value (if it is a number) to a string, then back to the original type. Cannot use prev version due to expo 50 complains. That is the only way it may work for me :( Pseudocode below: type SelectProps = {
value: string | number;
options: { value: string | number; label: string };
onChange: (value: any) => void;
}
const Select = ({ selectedValue, options, onChange }) => {
const originalValueType = useRef(
detectType(value),
);
const valueString = String(selectedValue);
const options = options.map((item) => ({ label: item.label, value: String(item.value) }));
const handleChange = (value: any) => {
onChange(
convertToType(value, originalValueType),
);
};
return (
<RNPickerSelect
value={valueString}
items={options}
onValueChange={handleChange}
/>
);
} |
Describe the bug
If value is a number, then it always defaults to the first item
Issue started happening after upgrading peer dependancy:
@react-native-picker/picker
to version2.6.1
To Reproduce
change values to numbers
Expected behavior
Value selected should change when using the picker
Screenshots
n/a
Additional details
Reproduction and/or code sample
The text was updated successfully, but these errors were encountered: