Skip to content

Instantly share code, notes, and snippets.

@unflores
Created February 8, 2019 14:26
Show Gist options
  • Save unflores/ea2fd82b29ec01d79d38ada5506fc4fb to your computer and use it in GitHub Desktop.
Save unflores/ea2fd82b29ec01d79d38ada5506fc4fb to your computer and use it in GitHub Desktop.
Gotta get them dots!
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