Created
September 20, 2024 08:37
-
-
Save zehan12/fc6e2f1644c209966a02784be90db117 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useEffect } from "react"; | |
| function MyComponent() { | |
| useEffect(() => { | |
| // Set up some side effect here, such as an event listener | |
| window.addEventListener("resize", handleResize); | |
| // Cleanup when the component unmounts | |
| return () => { | |
| window.removeEventListener("resize", handleResize); | |
| console.log("Component unmounted"); | |
| }; | |
| }, []); // Empty array ensures this runs only once | |
| const handleResize = () => { | |
| console.log("Window resized"); | |
| }; | |
| return <div>MyComponent is mounted!</div>; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment