ネイティブに反応して、axson.get(my_url_path)を使用してjsonデータを取得しようとしています。未解決のプロミス拒否(id:0):未定義はオブジェクトではありません( 'prevComponentInstance._currentElement')
}
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} />
)
}
}
:
Possible Unhandled Promise Rejection (id: 0): undefined is not an object ('prevComponentInstance._currentElement')....
私のコードは次の通りである:私は、この状態のキーを呼び出し、私が得たJSONからデータを読み取ろうと場合にresponse.dataでキー「urldatabase」、私はエラーを取得します
誰でもこのエラーが発生する理由を説明していただけますか?もし私が何か間違っていたら?
コンポーネントをコンストラクタにバインドできませんでしたか?適切なインデントを付けてファイル全体を追加してください。 コンストラクタのthis.state = {...}の後に、これを追加します。 '' 'javascript this.componentWillMount = this.componentWillMount.bind(this); '' ' –