Skip to content

Instantly share code, notes, and snippets.

@moimikey
Created March 18, 2015 04:34
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 moimikey/ce6da9b2a12146d403c0 to your computer and use it in GitHub Desktop.
Save moimikey/ce6da9b2a12146d403c0 to your computer and use it in GitHub Desktop.
React recursive timer animation
'use strict';
var React = require('react');
var Switch = React.createClass({
getInitialState: function() {
return {
switch: true
}
},
componentDidMount: function() {
this.interval = setInterval(this.flip, 1500);
},
componentWillUnmount: function() {
clearInterval(this.interval)
},
flip: function() {
this.setState({ switch: !this.state.switch });
},
render: function() {
return (
<div className={this.state.switch ? 'on' : 'off'}>
{this.state.switch ? 'on' : 'off'}
</div>
)
}
});
module.exports = Switch;
div{-webkit-transition:all .5s;text-transform:uppercase;}
.on{color:green;font-size:100px}
.off{color:red;font-size:50px}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment