Skip to content

Commit 2baf9fc

Browse files
authored
Merge pull request #3 from RSEnergyGroup/task/update-life-cycles
update lifecycle methods
2 parents 4115e1e + 4f38526 commit 2baf9fc

4 files changed

Lines changed: 19 additions & 20 deletions

File tree

build/Resizable.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ var Resizable = function (_React$Component) {
4848
}, _temp), _possibleConstructorReturn(_this, _ret);
4949
}
5050

51-
Resizable.prototype.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
51+
Resizable.prototype.componentDidUpdate = function componentDidUpdate(prevProps) {
5252
// If parent changes height/width, set that in our state.
53-
if (!this.state.resizing && (nextProps.width !== this.props.width || nextProps.height !== this.props.height)) {
53+
if (!this.state.resizing && (prevProps.width !== this.props.width || prevProps.height !== this.props.height)) {
5454
this.setState({
55-
width: nextProps.width,
56-
height: nextProps.height
55+
width: this.props.width,
56+
height: this.props.height
5757
});
5858
}
5959
};
@@ -151,7 +151,7 @@ var Resizable = function (_React$Component) {
151151
}
152152
var prevClient = _this2.state.prevClient;
153153

154-
// Calculate true deltas, this is needed to fix an issue with react-draggable not providing
154+
// Calculate true deltas, this is needed to fix an issue with react-draggable not providing
155155
// correct deltas on move
156156

157157
deltaX = prevClient[0] ? inverted ? prevClient[0] - clientX : clientX - prevClient[0] : deltaX;

build/ResizableBox.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ var ResizableBox = function (_React$Component) {
5959
}, _temp), _possibleConstructorReturn(_this, _ret);
6060
}
6161

62-
ResizableBox.prototype.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
63-
if (nextProps.width !== this.props.width || nextProps.height !== this.props.height) {
62+
ResizableBox.prototype.componentDidUpdate = function componentDidUpdate(prevProps) {
63+
if (prevProps.width !== this.props.width || prevProps.height !== this.props.height) {
6464
this.setState({
65-
width: nextProps.width,
66-
height: nextProps.height
65+
width: this.props.width,
66+
height: this.props.height
6767
});
6868
}
6969
};

lib/Resizable.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,12 @@ export default class Resizable extends React.Component<Props, State> {
116116
prevClient: [null, null]
117117
};
118118

119-
UNSAFE_componentWillReceiveProps(nextProps: Object) {
119+
componentDidUpdate(prevProps: Object) {
120120
// If parent changes height/width, set that in our state.
121-
if (!this.state.resizing &&
122-
(nextProps.width !== this.props.width || nextProps.height !== this.props.height)) {
121+
if (!this.state.resizing && (prevProps.width !== this.props.width || prevProps.height !== this.props.height)) {
123122
this.setState({
124-
width: nextProps.width,
125-
height: nextProps.height
123+
width: this.props.width,
124+
height: this.props.height
126125
});
127126
}
128127
}
@@ -200,7 +199,7 @@ export default class Resizable extends React.Component<Props, State> {
200199
}
201200
const { prevClient } = this.state;
202201

203-
// Calculate true deltas, this is needed to fix an issue with react-draggable not providing
202+
// Calculate true deltas, this is needed to fix an issue with react-draggable not providing
204203
// correct deltas on move
205204
deltaX = prevClient[0] ? (inverted ? prevClient[0] - clientX : clientX - prevClient[0]) : deltaX;
206205
deltaY = prevClient[1] ? clientY - prevClient[1] : deltaY;
@@ -230,7 +229,7 @@ export default class Resizable extends React.Component<Props, State> {
230229
if (width === this.state.width && height === this.state.height) return;
231230
newState.width = width;
232231
newState.height = height;
233-
232+
234233
// record client for next iteration
235234
newState.prevClient = [clientX, clientY];
236235
}

lib/ResizableBox.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ export default class ResizableBox extends React.Component<ResizableProps, State>
3535
}
3636
};
3737

38-
UNSAFE_componentWillReceiveProps(nextProps: ResizableProps) {
39-
if (nextProps.width !== this.props.width || nextProps.height !== this.props.height) {
38+
componentDidUpdate(prevProps: ResizableProps) {
39+
if (prevProps.width !== this.props.width || prevProps.height !== this.props.height) {
4040
this.setState({
41-
width: nextProps.width,
42-
height: nextProps.height
41+
width: this.props.width,
42+
height: this.props.height
4343
});
4444
}
4545
}

0 commit comments

Comments
 (0)