React 16.3 and createRef()

React 16.3 has been released: https://github.com/facebook/react/blob/master/CHANGELOG.md

We now have a new way of accessing refs, instead of the previous callback function. Per React’s docs, this is how it is done:

class MyComponent extends React.Component {
    constructor(props) {
        super(props);
        this.myRef = React.createRef();
    }
    render() {
        return <div ref={this.myRef} />;
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>