问题是这样的,比如知乎APP,它好像是每次打开一次APP都会刷新首页,于是我想在react native也想试一试,
我就写了个fetch的调用API,但是问题出现了,我把这个函数放在react组件中就会不停的调用,但是我写在组件外,就只调用一次,这是想要的,但是问题是,我不写在组件中,我就没有办法去渲染fetch调用成功后的数据,如果我写在组件中,那么就会死循环不停的调用fetch这个函数,我想问下,大家是怎么写的呢?
getMoviesFromApiAsync() {
return fetch('https://facebook.github.io/react-native/movies.json')
.then((response) => response.json())
.then((responseJson) => {
return responseJson.movies;
})
.catch((error) => {
console.error(error);
});
}
相关分类