Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of React component in Typescript using the useRef hook
import * as React from "react";
function HookRef() {
const divRef = React.useRef<HTMLDivElement>(null);
React.useEffect(() => {
if (divRef.current) {
console.log(`hookRef div width: ${divRef.current.clientWidth}`);
}
}, []);
return <div ref={divRef} style={{ width: "100%", height: "30px", backgroundColor: "orange" }} />;
}
export default HookRef;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.