Created
July 30, 2019 19:58
-
-
Save ChrisDobby/e0ba079486625470e08e72a551156469 to your computer and use it in GitHub Desktop.
Example of React component in Typescript using the useRef hook
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 * 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