0
그리드에 구현할 API의 이미지를로드하고 있습니다. 내 이미지는 정의되지 않았기 때문에 표시되지 않습니다. 내 구성 요소의 일부 기능은 다음과 같습니다. Images 및 isLoading은 모두 생성자에서 빈 배열 및 true로 정의됩니다.데이터를 올바르게로드하는 방법 네이티브 반응
componentWillMount() {
api().then((res) => {
this.state.images.push(res);
}).done();
this._load10Images();
this.setState({isLoading:false}); // is loading is set to false
} // after images loaded.
_getImageUrls(){
api().then((res) => {
this.state.images.push(res);
console.log(this.state.images); //right here works array is growing
console.log(this.state.images[0]);//with image uris
}).done();
}
_load10Images(){
for(let i=0; i<10; i++){
this._getImageUrls(); //call _getImageUrls 10 times to fill array
}
}
_loadImageGrid(){
if(this.state.isLoading){
return <Text>Loaading ...</Text>
}
else{
console.log(this.state.images[0]); // coming back as undefined
return <Text>not loading ...</Text>
}
}
render(){ return <View>
{this._loadImageGrid()}
</View>
}
이미지 배열은 render 함수와 _loadImageGrid 함수에서 정의되지 않은 상태로 되돌아옵니다.
상태 속성을 변경하는 것은 의미가 없습니다. setState를 사용하여 새로운 렌더 패스를 트리거해야합니다. – flq
@flq 나는 네가하는 말을 본 것 같아, 너는 정교 할 수 있니? –
하하, 답변보기 :) – flq