Skip to content

Instantly share code, notes, and snippets.

@vadik49b
Last active April 3, 2018 10:10
Show Gist options
  • Save vadik49b/20845665fc4f1f8f0090469c38f52fc4 to your computer and use it in GitHub Desktop.
Save vadik49b/20845665fc4f1f8f0090469c38f52fc4 to your computer and use it in GitHub Desktop.
import React from 'react'
const loaders = ['⣾', '⣽', '⣻', '⢿', '⡿', '⣟', '⣯', '⣷']
export default class AsciiLoadingIndicator extends React.Component {
state = {
loaderIndex: 0
}
componentDidMount () {
this.loaderChangeInterval = window.setInterval(() => {
this.setState((prevState) => {
return {
loaderIndex: (prevState.loaderIndex + 1) % loaders.length
}
})
}, 300)
}
componentWillUnmount () {
window.clearInterval(this.loaderChangeInterval)
}
render () {
return <span>{loaders[this.state.loaderIndex]}</span>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment