React native如何每隔x分钟从api获取一次

MeP*_*ePo 8 android react-native-android

我想在android上每隔x分钟运行一次fetch(使用React native)

function 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); }); 
}
Run Code Online (Sandbox Code Playgroud)

我开始使用documentaion中的示例,因为我还不确定如何进行此类提取.

我不知道我应该怎么开始这个(做一个Android本机处理程序可能?).我只找到了一个组件,但这是用于ios iOS后台获取API实现

小智 21

 componentDidMount(){
  this.timer = setInterval(()=> this.getMovies(), 1000)
 }

async getMovies(){

 fetch('https://facebook.github.io/react-native/movies.json', {method: "GET"})
  .then((response) => response.json())
  .then((responseData) =>
  {
    //set your data here
     console.log(responseData);
  })
  .catch((error) => {
      console.error(error);
  });

}
Run Code Online (Sandbox Code Playgroud)