GET 요청 (객체 배열)의 응답을 가져오고 배열의 템플릿 (templates)에 상태를 설정하려고합니다. 그러면 나중에이 코드에 액세스 할 수 있습니다. 그래서 같은 state.templates는 : 나는 setState를 줄이 주석하고 바로 응답을 기록 콘솔이있을 때React Native this2.state error
fetch('https://tiy-warmup.herokuapp.com/api/templates?token=' +
token)
.then(response => response.json())
.then(response => this.setState({templates: response}))
// .then(response => console.log(response))
, 나는 다시 올바른 배열을 얻을, 그래서 난 내 좋은 가져 오는 것을 알고있다.
Possible Unhandled Promise Rejection (id: 0):
_this2.setState is not a function
은 무엇이 오류 주위를 얻고 렌더링에 this.state.templates를 사용 할 수있을 해결책이 될 것이다 : 나는 setState를 줄을 실행하려고 할 때 그러나, 나는이 오류가? 기능을 결합 또는 기능을 화살표로 변경하거나, 당신이 당신의 약속을 catch
를 구현하지 않는 때문에
.catch(error => {
console.log('There has been a problem with your fetch operation: '+ error.message);
});
이 감사를 받아! 화살표 기능이 작동했습니다. –