In react native I am trying to get json data using axios.get(my_url_path), then I'm update my state with response.data to 'urldatabase' key ,if I trying to call this state key and read the data from the json that I got I get the error:
Possible Unhandled Promise Rejection (id: 0): undefined is not an object ('prevComponentInstance._currentElement')....
my code is as follow:
}
constructor(props) {
super(props);
this.state = { userAnswer: '', count: 0, urldatabase: {} };
}
componentWillMount(){
axios.get('my_url_path')
.then(response => this.setState({urldatabase: response.data}));
}
render() {
let num = this.state.count;
console.log(this.state.urldatabase[num].book)
const book = this.state.urldatabase[num].book
return(
<RiddleHeader headerText={book} />
)
}
}
Can anyone please explain why am I getting this error? what I done wrong if any?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…