1

I am using useEffect to make api call before the page is loading. But when I log the result, I see that it makes 2 console.log()s. How can I make this 1?

  useEffect(() => {
    // Function to make the Axios request
    const fetchData = async () => {
      try {
        //console.log("fetching data\n");
        await axios
          .get(
            "someurl.com/test",
            {}
          )
          .then((res) => {
            console.log("data: ", res.data);
          });
      } catch (err) {
        console.log("Error: ", err);
      }
    };
    fetchData();
  },[]); 
  • Does this happen in production? If not, then that's normal if you're running your app in [StrictMode](https://react.dev/reference/react/StrictMode#fixing-bugs-found-by-re-running-effects-in-development). – DallogFheir Aug 02 '23 at 16:23
  • It was about Strict Mode. Thank you! – Muhammed Didin Aug 02 '23 at 16:43

0 Answers0