Skip to content

Instantly share code, notes, and snippets.

@arnaudmolo
Last active August 29, 2015 14:17
Show Gist options
  • Save arnaudmolo/f701bfcabf76fa7e1df8 to your computer and use it in GitHub Desktop.
Save arnaudmolo/f701bfcabf76fa7e1df8 to your computer and use it in GitHub Desktop.
import React from 'react';
export default React.createClass({
animate(nextProps) {
const transition = d3
.select(this.getDOMNode())
.transition()
.duration(500);
Object.keys(nextProps).forEach(function(key) {
transition
.attr(key, nextProps[key]);
});
},
componentWillReceiveProps(nextProps) {
this.animate(nextProps);
},
shouldComponentUpdate(nextProps, nextState) {
return false;
},
render() {
return (
<circle {...this.props} />
);
}
});
@arnaudmolo
Copy link
Author

You could go a little further for .attr/.style animation, but the concept is easy to understand

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment