Reputation: 501
I am getting list of data from Rest api
an i am setting that data in the picker (drop down spinner).but its not working showing error please check my code and suggests some solution.
constructor(props)
{
super(props);
this.state = {
isLoading: true,
PickerValueHolder : ''
}
}
componentDidMount() {
this.FreelancerLevelSpinner();
}
FreelancerLevelSpinner = async ()=>{
return fetch('taxonomies/get_list?list=freelancer_level')
.then((response) => response.json())
.then((responseJson) => {
this.setState({
freelancerLevel: responseJson
}, function() {
// In this block you can do something with new state.
});
})
.catch((error) => {
console.error(error);
});
}
here i am setting the data in the picker...
<Picker
selectedValue={this.state.PickerValueHolder}
onValueChange={(itemValue, itemIndex) => this.setState({PickerValueHolder: itemValue})} >
{ this.state.freelancerLevel.map((item, key)=>(
<Picker.Item label={item.title} value={item.value} key={key} />)
)}
</Picker>
It is showing this error...
TypeError: TypeError: undefined is not an object (evaluating 'this.state.freelancerLevel.map')
Upvotes: 0
Views: 123
Reputation: 1499
You need to add freelancerLevel
to state initialization:
this.state = {
isLoading: true,
PickerValueHolder : '',
freelancerLevel: []
}
Upvotes: 4