From the course: React Hooks
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Introducing useEffect
- [Instructor] Another hook that is exported by the React library is useEffect. useEffect allows you to perform side effects in function components. So a side effect could be something like a console log, or it could interact with some kind of DOM API like history or window. So first we want to adjust our component here. So I'm going to get rid of everything related to our star. We had fun with our star rating, but it's time to move on. And then we're going to replace our star rating with a section. And the section will have a paragraph that says congratulations. And now we want to see that printed out. Perfect. So then we can use useEffect, but in order to use useEffect, we really need to set up a state variable. So first we'll set up a name and a function to change the state called setName. Then we'll call useState with some sort of an initial value. So the initial value we'll use here is Jan. Now, when we…