From the course: Build Modern Web Apps with React, Hooks, State Management, and APIs Using Vite or Next.js

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

useEffect problem

useEffect problem

Welcome back. In this video, we'll discuss the basic example, what we can do it in useEffect hook. That example will be for fetching data. Though this is a basic example, but it will give you an idea of what is the main feature of use effect that we will be doing almost most of the time in our react applications. But mastering it is very important as there are edge cases to that. If you do not master your use effect hook and all of its options and criterias, then you will be making pretty bad websites. I'm going to show you how. When we run our useEffect hook and we put inside any logic under it, then it run once when the component mounts on the UI. As we saw in the previous video's example that we put a console.log and by running that component on the UI, we ended up having our console.log. So by default, when the component mounts on the screen, useEffect runs once. This makes useEffect an ideal place for fetching data related to the component. For example, if you want to show up a…

Contents