Created
July 2, 2022 15:41
-
-
Save biomathcode/88373b1d500eea7541e66dfe9a522b6f to your computer and use it in GitHub Desktop.
This file contains 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 { useEffect, useRef } from "react"; | |
export default function App() { | |
// create a ref | |
const divElement = useRef(); | |
// trigger on the first render of the component | |
useEffect(() => { | |
// get the height of the div element | |
console.log( | |
"The height of the div is: ", divElement.current.offsetHeight | |
); | |
}, []); | |
return ( | |
<div ref={divElement}> | |
<h1>Learn about useRef!</h1> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment