問題是這樣的,比如知乎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); }); }
react native 調用fetch請求無奈問題
江戶川亂折騰
2018-11-22 18:14:32