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 hook: Introduction

useEffect hook: Introduction

Hello and welcome to lesson number 3. In this lesson, we'll understand the useEffect hook. Let's start off with what useEffect is. The useEffect hook lets us perform side effect functions in function components. Stuff like fetching data from the APIs, subscribing to events such as WebSockets or Redis events, setting up the timers or clearing them up, or if you want a direct DOM manipulation such as changing the page title, we can do that in UseEffect as well. That's how a basic useEffect usage looks like. We have to import the useEffect hook from React and inside an arrow function, we can provide the logic we want. Let's see that in action real quick. That's our previous hook project that we created. Inside this project, I have done a few changes. I have created a components folder. Inside this component folder, all the logic that we were directly using in the app component, I have created a component for that. That is useEffectHook. For the hook that we are learning now, we are going…

Contents