useEffect(() => // equivalent to componentDidMount console.log('Screen Mounted');
function useFetch(url) const [data, setData] = useState(null); const [loading, setLoading] = useState(true);
useEffect(() => fetch(url) .then(res => res.json()) .then(data => setData(data); setLoading(false); ); , [url]);
In the course, you will build a library of reusable custom hooks, including:
return () => clearInterval(intervalRef.current);