sam
sam

Reputation: 1

React-native - Dropdownpicker - undefined is not an object(evaluating 'choice.label')

I use DropDownPicker in react-native , When page loading i got this error

I use a DropDownPicker as follows :

                    <DropDownPicker
                        items={[
                          { label: 'Us', value: 'Us' },
                          { label: 'Canada, value: 'Canada' }
                        ]}
                        defaultValue={this.state.country}
                        containerStyle={{ height: 40 }}
                        style={{ backgroundColor: '#fafafa' }}
                        itemStyle={{
                          justifyContent: 'flex-start'
                        }}
                        dropDownStyle={{ backgroundColor: '#fafafa' }}
                        onChangeItem={item => this.setState({
                        country: item.value
                        })}
                      />

Upvotes: 0

Views: 2168

Answers (1)

Alex Mckay
Alex Mckay

Reputation: 3706

You are missing a ' with the word Canada:

items={[
   { label: 'Us', value: 'Us' },
   { label: 'Canada', value: 'Canada' }
]}

Reading Debug Messages

The choice.label error is a good hint that something is wrong with a label property being passed to DropDownPicker. Going forward definitely look out for little hints like this to help guide you to a solution.

Upvotes: 2

Related Questions