0

I have a React Native project. I need to fetch data. Some times the data I fetch my be empty. Is there a way to re-fetch after x amount of seconds if the data is not fetch or if there is a network error

const [data, setData]= useState([])

useEffect(()=> {
    axios
    .get("https://finalspaceapi.com/api/v0/character/?limit=2")
    .then(function (response) {
        console.log(response);
        setData(response.data)
    })
    .catch(()=>{
       console.log("error re-fetch")
    })

},[])
Jerry Seigle
  • 233
  • 4
  • 15

0 Answers0