Accepted answer

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


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