Skip to content

Instantly share code, notes, and snippets.

@joshwcomeau
Last active May 8, 2016 13:06
Show Gist options
  • Save joshwcomeau/e84f7538ce7f50e9718517d374a5d070 to your computer and use it in GitHub Desktop.
Save joshwcomeau/e84f7538ce7f50e9718517d374a5d070 to your computer and use it in GitHub Desktop.
letter-animation
import React, { Component } from 'react';
import random from 'lodash/random';
import sampleSize from 'lodash/sampleSize';
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
function getSubsetOfAlphabet() {
const numToPick = random(1, 26);
return sampleSize(alphabet, numToPick).sort();
}
class LetterDemo extends Component {
constructor(props) {
super(props);
this.state = {
letters: getSubsetOfAlphabet(),
};
}
componentWillMount() {
this.interval = window.setInterval(() => {
this.setState({
letters: getSubsetOfAlphabet(),
});
}, 1500);
}
componentWillUnmount() {
window.clearInterval(this.interval);
}
render() {
return (
<div className="letter-demo">
{this.state.letters.join('')}
</div>
);
}
}
export default LetterDemo;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment