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

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