So, that's the magic of it. The fact that it's an empty array mostly just means like nothing's ever going to change in the array. Like, I can put numbers in here. I can put text. I can put, I don't know, sup. Sup will never change. Exactly. It's not a valid dependency because it never changes. So, if it never changes, then it never reruns. So, that's how you must think. Okay.
So, this is because of the state that we talked about. I promise. Exactly. That's what you need to think about. I guess, I hope that makes sense. Okay.
So, now let's do something only when the counter changes. So, what I want to do is say, like, okay, toggle the fancy text, increase the counter, but I don't want it to run when the fancy text is toggled. So, let's put it here. Here. So, what we need to track is the years-past. So, we want to keep years-past, and the same, we want to say what, sorry, I forgot the English words, I'm just gonna go with, like, I'm just gonna go around it, around the English word. So, we want to say, whenever years-past changes, we want to run this again. Okay, cool. That makes perfect sense. Right? Yay! Okay, cool. So, when I increase the counter, it runs. But, but, and that's gonna, it runs on start, right? That's a problem, because we said we only wanted to run when years-past changed, but that's the catch, right? When your component bounds, years-past changed. I have an unmount for this component here in the index.js, and we can test that it runs again.
Comments