Skip to content

Commit 8ae0e38

Browse files
authored
Merge pull request #1846 from akiran/remove-unsafe
Remove UNSAFE_componentWillMount usage
2 parents bea916e + 8d9b8b6 commit 8ae0e38

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-slick",
3-
"version": "0.27.0",
3+
"version": "0.27.1",
44
"description": " React port of slick carousel",
55
"main": "./lib",
66
"files": [

src/inner-slider.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export class InnerSlider extends React.Component {
4040
this.callbackTimers = [];
4141
this.clickable = true;
4242
this.debouncedResize = null;
43+
const ssrState = this.ssrInit();
44+
this.state = { ...this.state, ...ssrState };
4345
}
4446
listRefHandler = ref => (this.list = ref);
4547
trackRefHandler = ref => (this.track = ref);
@@ -51,8 +53,7 @@ export class InnerSlider extends React.Component {
5153
this.list.style.height = getHeight(elem) + "px";
5254
}
5355
};
54-
UNSAFE_componentWillMount = () => {
55-
this.ssrInit();
56+
componentDidMount = () => {
5657
this.props.onInit && this.props.onInit();
5758
if (this.props.lazyLoad) {
5859
let slidesToLoad = getOnDemandLazySlides({
@@ -68,8 +69,6 @@ export class InnerSlider extends React.Component {
6869
}
6970
}
7071
}
71-
};
72-
componentDidMount = () => {
7372
let spec = { listRef: this.list, trackRef: this.track, ...this.props };
7473
this.updateState(spec, true, () => {
7574
this.adaptHeight();
@@ -264,10 +263,9 @@ export class InnerSlider extends React.Component {
264263
let currentWidth = `${childrenWidths[this.state.currentSlide]}px`;
265264
trackStyle.left = `calc(${trackStyle.left} + (100% - ${currentWidth}) / 2 ) `;
266265
}
267-
this.setState({
266+
return {
268267
trackStyle
269-
});
270-
return;
268+
};
271269
}
272270
let childrenCount = React.Children.count(this.props.children);
273271
const spec = { ...this.props, ...this.state, slideCount: childrenCount };
@@ -286,10 +284,10 @@ export class InnerSlider extends React.Component {
286284
width: trackWidth + "%",
287285
left: trackLeft + "%"
288286
};
289-
this.setState({
287+
return {
290288
slideWidth: slideWidth + "%",
291289
trackStyle: trackStyle
292-
});
290+
};
293291
};
294292
checkImagesLoad = () => {
295293
let images = this.list.querySelectorAll(".slick-slide img");

src/slider.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default class Slider extends React.Component {
2525
}
2626

2727
// handles responsive breakpoints
28-
UNSAFE_componentWillMount() {
28+
componentDidMount() {
2929
// performance monitoring
3030
//if (process.env.NODE_ENV !== 'production') {
3131
//const { whyDidYouUpdate } = require('why-did-you-update')

0 commit comments

Comments
 (0)