forked from adrian2x/odometer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathodometer.react.js
41 lines (35 loc) · 872 Bytes
/
odometer.react.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
38
39
40
41
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import Odometer from './odometer';
export default class ReactOdometer extends PureComponent {
static propTypes = {
animation: PropTypes.bool,
auto: PropTypes.bool,
duration: PropTypes.number,
format: PropTypes.string,
selector: PropTypes.string,
theme: PropTypes.string,
value: PropTypes.number.isRequired,
};
constructor(props) {
super(props);
this.node = React.createRef();
}
componentDidMount() {
const { value, ...options } = this.props;
this.odometer = new Odometer({
el: this.node.current,
value,
...options,
});
}
componentDidUpdate() {
const { value } = this.props;
this.odometer.update(value);
}
render() {
return React.createElement('div', {
ref: this.node,
});
}
}