Mid From PDF React React.js

How do you mimic componentDidMount and componentWillUnmount with hooks?

✅ componentDidMount:

useEffect(() => {

console.log("Component mounted");

}, []); // Empty array = run once on mount

✅ componentWillUnmount:

useEffect(() => {

const id = setInterval(() => console.log("tick"), 1000);
return () => {

clearInterval(id); // Cleanup

console.log("Component unmounted");

};

}, []);

More from React.js Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details