From the course: React: Creating and Hosting a Full-Stack Site

Schalten Sie den kompletten Kurs noch heute frei

Join today to access over 23,400 courses taught by industry experts.

Calling useEffect at the right time

Calling useEffect at the right time

"

- Okay. So we've added state and the use effect hook to our article page, and we've simulated data loading here. But before we move on to implementing the actual data fetching, right using Axios, there are two more caveats that we need to address. The first one is pretty subtle, but when it shows up, it really shows up. Okay. And if you're wondering what I mean by that and want to see it in action, let's say that for testing purposes, instead of just hard coding the number of up votes here inside our use effect hook, we generated a random number of up votes, between let's say one and 10. All right. So what that would look like, we would say up votes math dot ceiling, and then we would say math dot random and multiply that by 10. Right? So that's how you generate a number between one and 10, using JavaScripts math dot random, in case you weren't aware of that. All right. So after making that change, what you're…

Inhalt