Created
February 8, 2019 14:26
-
-
Save unflores/ea2fd82b29ec01d79d38ada5506fc4fb to your computer and use it in GitHub Desktop.
Gotta get them dots!
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 from 'react' | |
class Dots extends React.Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
dots: '', | |
timerID: null, | |
} | |
} | |
increaseDots = () => { | |
let { dots } = this.state | |
dots = dots.length > 2 ? '' : dots + '.' | |
this.setState({ dots }) | |
} | |
componentWillMount() { | |
const timerID = setInterval(() => { | |
this.increaseDots() | |
}, 1000) | |
this.setState({ timerID }) | |
} | |
componentWillUnmount() { | |
clearInterval(this.state.timerID) | |
} | |
render() { | |
return <span>{this.state.dots}</span> | |
} | |
} | |
export default Dots |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment