Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-native - Picker - undefined is not an object (evaluating 'this.props.children[position].props)

Tags:

react-native

I am encountering a weird behaviour when using Picker.

I use a Picker as follows :

<Picker
  mode="dropdown"
  style={styles.pickerField}
  selectedValue={this.state.dayAndTime}
  onValueChange={(text) => this.setState({ dayAndTime: text })}
>
  <Picker.Item label="Le 5/07 à 15H" value="0" key="0" />
</Picker>

When the screen displaying this picker is loaded, I got an error screen saying (cf. screenshot below) : undefined is not an object (evaluating 'this.props.children[position].props)

From what I gathered, my problem come from line 106 of Libraries/Components/Picker/PickerAndroid.android.js, it seems that having a property "onValueChange" triggers it. I removed it, and error didn't happen.

I use react-native 0.31.0, I use an android api 23 virtual device with genymotion.

Is there something something I am doing wrong ?

enter image description here

like image 686
vincenth Avatar asked Dec 19 '22 14:12

vincenth


2 Answers

The above solutions might be the one that might solve your query. One thing I would put light on is , correct way to import:

import {Picker} from '@react-native-community/picker';

Rather than

import Picker from '@react-native-community/picker';
like image 129
Adit Alware Avatar answered Jun 01 '23 02:06

Adit Alware


There must be at least 2 items to pick from, for example: <Picker.Item label="Le 5/07 à 15H" value="0" key="0" /> <Picker.Item label="Le 5/07 à 15H" value="1" key="1" />

Also for better syntax you can try: onValueChange={(dayAndTime) => this.setState({ dayAndTime })}

like image 44
Wojtek Szafraniec Avatar answered Jun 01 '23 00:06

Wojtek Szafraniec