Skip to content

Commit c80dad7

Browse files
authored
Remove deprecated lifecycle from <Interval /> and fix its treeshaking (#91)
In this diff I replaced deprecated `componentWillReceiveProps` with `componentDidUpdate` which should be used for side effects (which implements this component). To fix Interval component treeshakability I got rid from `defaultProps` static property.
1 parent b334588 commit c80dad7

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

.size-snapshot.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
{
22
"dist/react-powerplug.umd.js": {
3-
"bundled": 24185,
4-
"minified": 10002,
5-
"gzipped": 2571
3+
"bundled": 24029,
4+
"minified": 9906,
5+
"gzipped": 2565
66
},
77
"dist/react-powerplug.cjs.js": {
8-
"bundled": 21058,
9-
"minified": 10885,
10-
"gzipped": 2423
8+
"bundled": 20918,
9+
"minified": 10782,
10+
"gzipped": 2414
1111
},
1212
"dist/react-powerplug.esm.js": {
13-
"bundled": 20412,
14-
"minified": 10336,
15-
"gzipped": 2296,
13+
"bundled": 20272,
14+
"minified": 10233,
15+
"gzipped": 2286,
1616
"treeshaked": {
17-
"rollup": 3115,
18-
"webpack": 3581
17+
"rollup": 1489,
18+
"webpack": 1939
1919
}
2020
}
2121
}

src/components/Interval.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ import { Component } from 'react'
22
import renderProps from '../utils/renderProps'
33

44
class Interval extends Component {
5-
static defaultProps = {
6-
delay: 1000,
7-
}
8-
95
state = {
106
times: 0,
117
}
@@ -32,7 +28,10 @@ class Interval extends Component {
3228
}
3329

3430
start = delay => {
35-
const _delay = typeof delay === 'number' ? delay : this.props.delay
31+
const _delay =
32+
typeof delay === 'number'
33+
? delay
34+
: this.props.delay != null ? this.props.delay : 1000
3635
this._setIntervalIfNecessary(_delay)
3736
}
3837

@@ -44,10 +43,10 @@ class Interval extends Component {
4443
this.start()
4544
}
4645

47-
componentWillReceiveProps(nextProps) {
48-
if (this.props.delay !== nextProps.delay) {
46+
componentDidUpdate(prevProps) {
47+
if (prevProps.delay !== this.props.delay) {
4948
this.stop()
50-
this.start(nextProps.delay)
49+
this.start()
5150
}
5251
}
5352

0 commit comments

Comments
 (0)