0
function Homepage() {
    const url = `https://cloud.iexapis.com/stable/stock/aapl/quote?token=token`;
    useEffect(()=>{
        axios.get(url)
        .then(res => {
            console.log(res.data);
        })
        .catch(err => {
            console.log(err);
        })
    }, [])
}

I'm trying to fetch data from the api, but why this code gives me two identical responses.enter image description here

How should I fix it, so I can get only one response from api?

xSwampy
  • 35
  • 3

1 Answers1

1

It does run twice in dev mode on React 18, You will not have this behavior on production

You can turn it off by deleting <React.StrictMode /> but i don't recommend that, since StrictMode will help you to catch problems in your components during development

Fateh Mohamed
  • 20,445
  • 5
  • 43
  • 52