From the course: React Foundations by Pearson
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Introduction to React.useEffect - React.js Tutorial
From the course: React Foundations by Pearson
Introduction to React.useEffect
Okay, in this topic, we're going to start looking at the UseEffect hook in the React library. Quite different from UseState, each hook has its own purpose. The purpose of React UseEffect, it enables a functional component to register some side effect code that you would like to be executed after each time the component's rendered. So a side effect is anything that's not user interface. So it could be to start a timer or to call a REST service after the components been rendered, call a REST service to update data in the database, for example, or to subscribe to a WebSocket. So you can start having a conversation with a WebSocket server or whatever. Anything non-graphical that you would like to do after each render of a component, useEffect is what you need to do. This is how it looks. You call react useEffect, and you pass in a lambda. So here is the lambda. I draw it carefully. That is the lambda. And that code will be, React will basically register that code, and it'll run that code,…
Contents
-
-
-
-
-
-
-
(Locked)
Learning objectives1m 16s
-
(Locked)
Getting started with hooks5m 58s
-
(Locked)
Introduction to React.useState13m 55s
-
(Locked)
Realistic example of React.useState11m 58s
-
(Locked)
Introduction to React.useEffect6m 28s
-
(Locked)
Defining cleanup behavior for an effect10m 24s
-
(Locked)
Defining effects with dependencies11m 51s
-
(Locked)
Lab: Hooks12m 8s
-
(Locked)
Lab solution: Hooks8m 8s
-
(Locked)
-
-
-
-
-
-
-
-