DEV Community

Discussion on: Introduction to React Hooks

Collapse
 
gixxerblade profile image
Steve Clark 🤷‍♀️

Great article! Straight to the point. One issue I ran into was not wrapping useEffect() around another function. One example was a fetch function.

  useEffect(() => {
    const fetchData = async () => {
      const response = await fetch(url, options);
      const data = await response.json();
      const [item] = data.results;
      setData(item);
      setLoading(false);
    };
    fetchData();
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);

As you can see I wrapped the useEffect() around the fetchdata() function. The
// eslint-disable-next-line react-hooks/exhaustive-deps comment was a whole other issue.