Skip to content

Instantly share code, notes, and snippets.

@geetotes
Last active May 15, 2017 18:58
Show Gist options
  • Save geetotes/f9c0e81e6489c0801cca089175ce70ab to your computer and use it in GitHub Desktop.
Save geetotes/f9c0e81e6489c0801cca089175ce70ab to your computer and use it in GitHub Desktop.
class PrettyLoader extends React.Component {
constructor(props) {
super(props);
this.state = {
loading: false
};
this.setLoading = this.setLoading.bind(this);
}
componentDidMount() {
window.addEventListener('loader', this.setLoading, false);
}
componentWillUnmount() {
window.removeEventListener('loader', this.setLoading, false);
}
setLoading(evt) {
this.setState({
loading: evt.detail
});
}
render() {
let loaderStyles = classNames({
'hidden': this.state.loading
});
return(
<div>
<div className={loaderStyles} />
{this.props.children}
</div>
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment