Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Example of React component in Typescript using createRef
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
You can’t perform that action at this time.