From the course: React: State Management
Unlock the full course today
Join today to access over 25,200 courses taught by industry experts.
useEffect: Apply side effects - React.js Tutorial
From the course: React: State Management
useEffect: Apply side effects
- [Instructor] useEffect is another React hook that lets you apply side effects on every render based on the latest props and a previous state. useEffect takes two parameters, a callback function and a list of dependencies. This allows to apply side effects whenever there is a change in the state within the components. In our example, we want to verify if the user input matches two values added together, then apply side effects based on the results based on whether the answer is right or wrong. Back in Codespaces, I made some changes and decided to include parts of the code into components to make the code better organized into multiple components. This is a key feature of the React library which is called composition, which is to divide and organize the UI into small units. And you're going to see that inside the root components app. We now have child components, and now we share the state by passing data as props. And based…