1
我试图使用fetch从api获取数据。控制台日志是给我正确的JSON,但我发现了以下错误试图设置状态时:当设置状态时,是什么导致了这种TypeError?
类型错误:未定义无法读取属性“的setState”(...)
getInitialState() {
return {
checklist: {},
documents: [],
questions: [],
faqs: [],
hospitals: [],
profile: {},
guarantor: {},
}
},
componentDidMount(){
this.fetchUser(1);
this.fetchFaqs();
},
fetchFaqs() {
fetch(FAQ_API)
.then(function(response){
return response.json();
})
.then(function(json){
console.log("faqs: " , json);
this.setState({
faqs: json,
});
})
.catch((error) => {
console.warn(error);
});
},