Search code examples
reactjsaxioshttprequestweb-deploymentgithub-pages

https requests with axios not made in deployment mode in REACT


I'm fetching a json file using axios in my react project. The rquest is made and I get a response on my localhost. However, on github pages when I deploy, the request is not made. I double checked using the networks tab in chrome devtools.

My code

enter image description here

the url I'm requesting: here


Solution

  • You are making the request when your component unmounts (cleanup function) instead on its mount. Instead of returning a function in useEffect you should do the request directly.

    useEffect(() => {
      axios.get('https://scaleflex.cloudimg.io/v7/0.fe_task_static/pictures.json?vh=7a646d&func=proxy').then((res) => {
        setImages(res.data);
      });
    }, []);