Advanced - 10- Fetching Data with Hooks - BUG found

I noticed there is tiny bug in useEffect function. It should pass an empty array [] argument. Otherwise, it fetches every 20ms.

@Mosh: please update video.

  useEffect(() => {
    const getUsers = async () => {
      const result = await axios('');

  }, []);
1 Like

I was about to post this same issue. I don’t know if it’s because I’m used to Class Components but so far hooks don’t feel right to me.

Same here.
When working on context, I noticed some perf issues.
The network tab showed constant API calls.
That’s weird because the data itself does not change, so we would assume there is no rerender of the DOM for the data does not change.

Went on StackOverflow because setting the dependency array to users does not help.

Solution from StackOverflow.

There is an article that explains why this happens even though we put a seemingly proper state property in the dependency array.

Article on inf loops with useEffect.

Kind Regards.