fetch
関数を使用して受け取ったpromise
から状態を更新しようとしています。プロミスのthen関数からsetStateを設定できませんでした
componentDidMount(){
fetch(url).then((responseText) => {
var response = responseText.json();
response.then(function(response){
this.setState(response);
});
});
}
IはsetState
関数そして
ないというエラーを取得し、私は以下のようthis
値を渡すbind(this)
しようとしました。
componentDidMount(){
fetch(url).then((responseText) => {
var response = responseText.json();
response.then(function(response){
this.setState(response);
});
}).bind(this);
}
現在は動作していません。もう一度同じエラーが発生します。
私は皮肉なことに、このメソッドを読むことができます。 – ApertureSecurity