Created
July 30, 2019 20:00
-
-
Save ChrisDobby/ae5f22fcce5388fd54512acac5adaaa2 to your computer and use it in GitHub Desktop.
Example of React component in Typescript using createRef
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"; | |
class CreateRef extends React.Component { | |
divRef = React.createRef<HTMLDivElement>(); | |
componentDidMount() { | |
if (this.divRef.current) { | |
console.log(`createRefRef div width: ${this.divRef.current.clientWidth}`); | |
} | |
} | |
render() { | |
return <div ref={this.divRef} style={{ width: "100%", height: "30px", backgroundColor: "blue" }} />; | |
} | |
} | |
export default CreateRef; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment