Last active
January 6, 2018 11:32
-
-
Save oliviertassinari/fa1cd34a3fff67553631606109bed124 to your computer and use it in GitHub Desktop.
Get a reference on the DOM element.
This file contains 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 React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import PropTypes from 'prop-types'; | |
class RootRef extends React.Component { | |
componentDidMount() { | |
this.props.rootRef(ReactDOM.findDOMNode(this)) | |
} | |
componentWillUnmount() { | |
this.props.rootRef(null) | |
} | |
render() { | |
return this.props.children | |
} | |
} | |
RootRef.propTypes = { | |
children: PropTypes.element.isRequired, | |
rootRef: PropTypes.func.isRequired, | |
}; | |
export default RootRef; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of usage: