Skip to content

Instantly share code, notes, and snippets.

@biomathcode
Created July 2, 2022 15:41
Show Gist options
  • Save biomathcode/88373b1d500eea7541e66dfe9a522b6f to your computer and use it in GitHub Desktop.
Save biomathcode/88373b1d500eea7541e66dfe9a522b6f to your computer and use it in GitHub Desktop.
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