Skip to content

Commit 97988e8

Browse files
committed
Added UNSAFE_ prefix to deprecated lifecycle methods to avoid warnings in React 16.9
1 parent 640ce00 commit 97988e8

File tree

3 files changed

+16
-25
lines changed

3 files changed

+16
-25
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.24.0",
3+
"version": "0.25.0",
44
"description": " React port of slick carousel",
55
"main": "./lib",
66
"files": [

src/inner-slider.js

+10-13
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class InnerSlider extends React.Component {
5252
this.list.style.height = getHeight(elem) + "px";
5353
}
5454
};
55-
componentWillMount = () => {
55+
UNSAFE_componentWillMount = () => {
5656
this.ssrInit();
5757
this.props.onInit && this.props.onInit();
5858
if (this.props.lazyLoad) {
@@ -107,7 +107,7 @@ export class InnerSlider extends React.Component {
107107
window.attachEvent("onresize", this.onWindowResized);
108108
}
109109
};
110-
componentWillUnmount = () => {
110+
UNSAFE_componentWillUnmount = () => {
111111
if (this.animationEndCallback) {
112112
clearTimeout(this.animationEndCallback);
113113
}
@@ -127,7 +127,7 @@ export class InnerSlider extends React.Component {
127127
clearInterval(this.autoplayTimer);
128128
}
129129
};
130-
componentWillReceiveProps = nextProps => {
130+
UNSAFE_componentWillReceiveProps = nextProps => {
131131
let spec = {
132132
listRef: this.list,
133133
trackRef: this.track,
@@ -264,9 +264,7 @@ export class InnerSlider extends React.Component {
264264
};
265265
if (this.props.centerMode) {
266266
let currentWidth = `${childrenWidths[this.state.currentSlide]}px`;
267-
trackStyle.left = `calc(${
268-
trackStyle.left
269-
} + (100% - ${currentWidth}) / 2 ) `;
267+
trackStyle.left = `calc(${trackStyle.left} + (100% - ${currentWidth}) / 2 ) `;
270268
}
271269
this.setState({
272270
trackStyle
@@ -276,15 +274,15 @@ export class InnerSlider extends React.Component {
276274
let childrenCount = React.Children.count(this.props.children);
277275
const spec = { ...this.props, ...this.state, slideCount: childrenCount };
278276
let slideCount = getPreClones(spec) + getPostClones(spec) + childrenCount;
279-
let trackWidth = 100 / this.props.slidesToShow * slideCount;
277+
let trackWidth = (100 / this.props.slidesToShow) * slideCount;
280278
let slideWidth = 100 / slideCount;
281279
let trackLeft =
282-
-slideWidth *
283-
(getPreClones(spec) + this.state.currentSlide) *
284-
trackWidth /
280+
(-slideWidth *
281+
(getPreClones(spec) + this.state.currentSlide) *
282+
trackWidth) /
285283
100;
286284
if (this.props.centerMode) {
287-
trackLeft += (100 - slideWidth * trackWidth / 100) / 2;
285+
trackLeft += (100 - (slideWidth * trackWidth) / 100) / 2;
288286
}
289287
let trackStyle = {
290288
width: trackWidth + "%",
@@ -390,8 +388,7 @@ export class InnerSlider extends React.Component {
390388
);
391389
onLazyLoad && slidesToLoad.length > 0 && onLazyLoad(slidesToLoad);
392390
this.setState(state, () => {
393-
asNavFor &&
394-
asNavFor.innerSlider.slideHandler(index);
391+
asNavFor && asNavFor.innerSlider.slideHandler(index);
395392
if (!nextState) return;
396393
this.animationEndCallback = setTimeout(() => {
397394
const { animating, ...firstBatch } = nextState;

src/slider.js

+5-11
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-
componentWillMount() {
28+
UNSAFE_componentWillMount() {
2929
// performance monitoring
3030
//if (process.env.NODE_ENV !== 'production') {
3131
//const { whyDidYouUpdate } = require('why-did-you-update')
@@ -67,7 +67,7 @@ export default class Slider extends React.Component {
6767
}
6868
}
6969

70-
componentWillUnmount() {
70+
UNSAFE_componentWillUnmount() {
7171
this._responsiveMediaHandlers.forEach(function(obj) {
7272
enquire.unregister(obj.query, obj.handler);
7373
});
@@ -106,9 +106,7 @@ export default class Slider extends React.Component {
106106
process.env.NODE_ENV !== "production"
107107
) {
108108
console.warn(
109-
`slidesToScroll should be equal to 1 in centerMode, you are using ${
110-
settings.slidesToScroll
111-
}`
109+
`slidesToScroll should be equal to 1 in centerMode, you are using ${settings.slidesToScroll}`
112110
);
113111
}
114112
settings.slidesToScroll = 1;
@@ -117,19 +115,15 @@ export default class Slider extends React.Component {
117115
if (settings.fade) {
118116
if (settings.slidesToShow > 1 && process.env.NODE_ENV !== "production") {
119117
console.warn(
120-
`slidesToShow should be equal to 1 when fade is true, you're using ${
121-
settings.slidesToShow
122-
}`
118+
`slidesToShow should be equal to 1 when fade is true, you're using ${settings.slidesToShow}`
123119
);
124120
}
125121
if (
126122
settings.slidesToScroll > 1 &&
127123
process.env.NODE_ENV !== "production"
128124
) {
129125
console.warn(
130-
`slidesToScroll should be equal to 1 when fade is true, you're using ${
131-
settings.slidesToScroll
132-
}`
126+
`slidesToScroll should be equal to 1 when fade is true, you're using ${settings.slidesToScroll}`
133127
);
134128
}
135129
settings.slidesToShow = 1;

0 commit comments

Comments
 (0)