Last active
May 8, 2016 13:06
-
-
Save joshwcomeau/e84f7538ce7f50e9718517d374a5d070 to your computer and use it in GitHub Desktop.
letter-animation
This file contains hidden or 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, { 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