Last active
April 3, 2018 10:10
-
-
Save vadik49b/20845665fc4f1f8f0090469c38f52fc4 to your computer and use it in GitHub Desktop.
This file contains 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' | |
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