-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathmain.js
37 lines (31 loc) · 839 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import Spinner from 'spin.js';
class ReactSpinner extends PureComponent {
static propTypes = {
config: PropTypes.object,
stopped: PropTypes.bool
};
componentDidMount() {
this.spinner = new Spinner(this.props.config);
if (!this.props.stopped) {
this.spinner.spin(this.container);
}
}
componentWillReceiveProps(newProps) {
if (newProps.stopped === true && !this.props.stopped) {
this.spinner.stop();
} else if (!newProps.stopped && this.props.stopped === true) {
this.spinner.spin(this.container);
}
}
componentWillUnmount() {
this.spinner.stop();
}
render() {
return (
<span ref={(container) => (this.container = container)} />
);
}
}
export default ReactSpinner;