Skip to content

Commit

Permalink
Added UNSAFE_ prefix to deprecated lifecycle methods to avoid warning…
Browse files Browse the repository at this point in the history
…s in React 16.9
  • Loading branch information
akiran committed Aug 10, 2019
1 parent 640ce00 commit 97988e8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-slick",
"version": "0.24.0",
"version": "0.25.0",
"description": " React port of slick carousel",
"main": "./lib",
"files": [
Expand Down
23 changes: 10 additions & 13 deletions src/inner-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class InnerSlider extends React.Component {
this.list.style.height = getHeight(elem) + "px";
}
};
componentWillMount = () => {
UNSAFE_componentWillMount = () => {
this.ssrInit();
this.props.onInit && this.props.onInit();
if (this.props.lazyLoad) {
Expand Down Expand Up @@ -107,7 +107,7 @@ export class InnerSlider extends React.Component {
window.attachEvent("onresize", this.onWindowResized);
}
};
componentWillUnmount = () => {
UNSAFE_componentWillUnmount = () => {

This comment has been minimized.

Copy link
@afc163

afc163 Aug 12, 2019

Contributor

UNSAFE_componentWillUnmount do not existed, see reactjs/react-lifecycles-compat#47 (comment)

This comment has been minimized.

Copy link
@afc163

afc163 Aug 12, 2019

Contributor

created a PR: #1615

if (this.animationEndCallback) {
clearTimeout(this.animationEndCallback);
}
Expand All @@ -127,7 +127,7 @@ export class InnerSlider extends React.Component {
clearInterval(this.autoplayTimer);
}
};
componentWillReceiveProps = nextProps => {
UNSAFE_componentWillReceiveProps = nextProps => {
let spec = {
listRef: this.list,
trackRef: this.track,
Expand Down Expand Up @@ -264,9 +264,7 @@ export class InnerSlider extends React.Component {
};
if (this.props.centerMode) {
let currentWidth = `${childrenWidths[this.state.currentSlide]}px`;
trackStyle.left = `calc(${
trackStyle.left
} + (100% - ${currentWidth}) / 2 ) `;
trackStyle.left = `calc(${trackStyle.left} + (100% - ${currentWidth}) / 2 ) `;
}
this.setState({
trackStyle
Expand All @@ -276,15 +274,15 @@ export class InnerSlider extends React.Component {
let childrenCount = React.Children.count(this.props.children);
const spec = { ...this.props, ...this.state, slideCount: childrenCount };
let slideCount = getPreClones(spec) + getPostClones(spec) + childrenCount;
let trackWidth = 100 / this.props.slidesToShow * slideCount;
let trackWidth = (100 / this.props.slidesToShow) * slideCount;
let slideWidth = 100 / slideCount;
let trackLeft =
-slideWidth *
(getPreClones(spec) + this.state.currentSlide) *
trackWidth /
(-slideWidth *
(getPreClones(spec) + this.state.currentSlide) *
trackWidth) /
100;
if (this.props.centerMode) {
trackLeft += (100 - slideWidth * trackWidth / 100) / 2;
trackLeft += (100 - (slideWidth * trackWidth) / 100) / 2;
}
let trackStyle = {
width: trackWidth + "%",
Expand Down Expand Up @@ -390,8 +388,7 @@ export class InnerSlider extends React.Component {
);
onLazyLoad && slidesToLoad.length > 0 && onLazyLoad(slidesToLoad);
this.setState(state, () => {
asNavFor &&
asNavFor.innerSlider.slideHandler(index);
asNavFor && asNavFor.innerSlider.slideHandler(index);
if (!nextState) return;
this.animationEndCallback = setTimeout(() => {
const { animating, ...firstBatch } = nextState;
Expand Down
16 changes: 5 additions & 11 deletions src/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class Slider extends React.Component {
}

// handles responsive breakpoints
componentWillMount() {
UNSAFE_componentWillMount() {
// performance monitoring
//if (process.env.NODE_ENV !== 'production') {
//const { whyDidYouUpdate } = require('why-did-you-update')
Expand Down Expand Up @@ -67,7 +67,7 @@ export default class Slider extends React.Component {
}
}

componentWillUnmount() {
UNSAFE_componentWillUnmount() {
this._responsiveMediaHandlers.forEach(function(obj) {
enquire.unregister(obj.query, obj.handler);
});
Expand Down Expand Up @@ -106,9 +106,7 @@ export default class Slider extends React.Component {
process.env.NODE_ENV !== "production"
) {
console.warn(
`slidesToScroll should be equal to 1 in centerMode, you are using ${
settings.slidesToScroll
}`
`slidesToScroll should be equal to 1 in centerMode, you are using ${settings.slidesToScroll}`
);
}
settings.slidesToScroll = 1;
Expand All @@ -117,19 +115,15 @@ export default class Slider extends React.Component {
if (settings.fade) {
if (settings.slidesToShow > 1 && process.env.NODE_ENV !== "production") {
console.warn(
`slidesToShow should be equal to 1 when fade is true, you're using ${
settings.slidesToShow
}`
`slidesToShow should be equal to 1 when fade is true, you're using ${settings.slidesToShow}`
);
}
if (
settings.slidesToScroll > 1 &&
process.env.NODE_ENV !== "production"
) {
console.warn(
`slidesToScroll should be equal to 1 when fade is true, you're using ${
settings.slidesToScroll
}`
`slidesToScroll should be equal to 1 when fade is true, you're using ${settings.slidesToScroll}`
);
}
settings.slidesToShow = 1;
Expand Down

0 comments on commit 97988e8

Please sign in to comment.