Picker: cannot read property 'value' of undefined when `items` is an empty array
drzamich opened this issue · comments
Description
When items
passed to <Picker />
is an empty array (e.g. due to filtering using Search), app crashes.
This is due to the fact that in PickerItemsList.tsx
when initializing wheelPickerValue
on line 38
it's assumed that if items
is defined, there is at least one item:
const [wheelPickerValue, setWheelPickerValue] = useState(context.value ?? items?.[0].value);
an extra ?
for optional chaining will solve the issue:
items?.[0]?.value
Workaround
Don't pass an empty array as items
. Instead you can pass a null
for example.
Related to
- Components
- Demo
- Docs
- Typings
Steps to reproduce
Expected behavior
App doesn't crash
Actual behavior
App crashes with an error
TypeError: Cannot read property 'value' of undefined
This error is located at:
in PickerItemsList (at picker/index.js:193)
in RCTView (at View.js:116)
in View (at view/index.js:92)
in View (at modal/index.js:81)
in RCTView (at View.js:116)
in View (at AppContainer.js:127)
More Info
Code snippet
<Picker items={[]} />
Screenshots/Video
Environment
- React Native version:
0.73.2
- React Native UI Lib version:
7.16.0
Affected platforms
- Android
- iOS
- Web