how to fetch data using useeffect code example
Example 1: how to fetch data with useEffect
useEffect(() => {
const fetchData = async () => {
const result = await fetch(
'https://my-api.com',
);
setState(result);
};
fetchData();
}, []);
Example 2: How to fetch data from an api useEffect
import {useEffect} from "react";
useEffect(() => {
fetchData();
}, []);