Skip to content

Instantly share code, notes, and snippets.

@joshwcomeau
Last active February 12, 2016 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshwcomeau/5b0f0f6c9642930d813e to your computer and use it in GitHub Desktop.
Save joshwcomeau/5b0f0f6c9642930d813e to your computer and use it in GitHub Desktop.
Animating the Unanimatable
class ArticleList extends Component {
componentWillReceiveProps() {
this.props.children.forEach( child => {
// Find the ref for this specific child.
const ref = this.refs[child.key]
// Look up the DOM node
const domNode = ReactDOM.findDOMNode( ref );
// Calculate the bounding box
const boundingBox = domNode.getBoundingClientRect();
// Store that box in the state, by its key.
this.setState({
[child.key]: boundingBox
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment