私の反応クラスでこの問題があります。自分の状態を更新しようとしていますが、このエラーが発生します。 "未定義のsetState 'プロパティを読み取れません。オンラインすべてのソリューションを試してみましたが、運、ここ'this.setState'で何が問題なのですか?
はコード
export default class PageBackground extends Component{
constructor(props) {
super(props);
this.state={
lat :'nothing',
longi :''
};
this.getLocation=this.getLocation.bind(this);
}
componentWillMount() {
this.getLocation();
}
getLocation() {
fetch('http://freegeoip.net/json/')
.then((res)=>res.json())
.then(function (objec){this.setState({lat:objec.latitude,longi:objec.longitude});})
.catch((err)=>console.log("didn't connect to App",err))
console.log(this.state.lat)
}
render(){
return(
<p>{this.state.lat}</p>
)
}
}
コンソールログは入手できますか? – buoyantair
「this」は関数のコンテキスト内にあると思います。たぶんあなたは 'that = this'と' that.setState'を試してみるべきでしょう – AnkitG
この非常に重大な誤りは、文字通り何百万もの重複があります。私はあなたがそれらのどれかを見つけることができなかったことに驚いています。 – Chris