Skip to content
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

Picker: cannot read property 'value' of undefined when items is an empty array #2936

Open
4 of 7 tasks
drzamich opened this issue Feb 4, 2024 · 0 comments · May be fixed by #3044
Open
4 of 7 tasks

Picker: cannot read property 'value' of undefined when items is an empty array #2936

drzamich opened this issue Feb 4, 2024 · 0 comments · May be fixed by #3044
Labels
bug a bug in one of the components

Comments

@drzamich
Copy link

drzamich commented Feb 4, 2024

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

image

Environment

  • React Native version: 0.73.2
  • React Native UI Lib version: 7.16.0

Affected platforms

  • Android
  • iOS
  • Web
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug a bug in one of the components
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant