score:0

Accepted answer

You should call APIs in useEffect() hook, your api will be called when the component has mounted:

Ex:

useEffect(() => {
  (async() {
    const data = await fetch(...);
    // do something with the data 
  })
}, []) // passing empty dependency for useEffect it should be called one time when component mounted `

Related Query

More Query from same tag