DEV Community

Discussion on: React Hooks: useEffect

Collapse
 
jhavn profile image
jhavn

I do wonder why you're no longer adding a class to an element in your examples. I might be wrong, but your examples don't answer the question in your first paragraph: how do you add a class (via classList.add) to an element that hasn't yet been found by React?

Collapse
 
hajarnasr profile image
Hajar | هاجر • Edited

Yeah, I didn't use an example to answer that question (sorry). However, I think what I wanted to say was that if we wanted to add some code that depended on the component's render, useEffect would be the right place to add that code. Because it gets called after all the elements are painted on the page. :)