@@ -122,47 +122,33 @@ export class InnerSlider extends React.Component {
122122 }
123123 this . ro . disconnect ( ) ;
124124 } ;
125- UNSAFE_componentWillReceiveProps = nextProps => {
126- let spec = {
127- listRef : this . list ,
128- trackRef : this . track ,
129- ...nextProps ,
130- ...this . state
131- } ;
125+
126+ didPropsChange ( prevProps ) {
132127 let setTrackStyle = false ;
133128 for ( let key of Object . keys ( this . props ) ) {
134- if ( ! nextProps . hasOwnProperty ( key ) ) {
129+ if ( ! prevProps . hasOwnProperty ( key ) ) {
135130 setTrackStyle = true ;
136131 break ;
137132 }
138133 if (
139- typeof nextProps [ key ] === "object" ||
140- typeof nextProps [ key ] === "function"
134+ typeof prevProps [ key ] === "object" ||
135+ typeof prevProps [ key ] === "function"
141136 ) {
142137 continue ;
143138 }
144- if ( nextProps [ key ] !== this . props [ key ] ) {
139+ if ( prevProps [ key ] !== this . props [ key ] ) {
145140 setTrackStyle = true ;
146141 break ;
147142 }
148143 }
149- this . updateState ( spec , setTrackStyle , ( ) => {
150- if ( this . state . currentSlide >= React . Children . count ( nextProps . children ) ) {
151- this . changeSlide ( {
152- message : "index" ,
153- index :
154- React . Children . count ( nextProps . children ) - nextProps . slidesToShow ,
155- currentSlide : this . state . currentSlide
156- } ) ;
157- }
158- if ( nextProps . autoplay ) {
159- this . autoPlay ( "update" ) ;
160- } else {
161- this . pause ( "paused" ) ;
162- }
163- } ) ;
164- } ;
165- componentDidUpdate = ( ) => {
144+ return (
145+ setTrackStyle ||
146+ React . Children . count ( this . props . children ) !==
147+ React . Children . count ( prevProps . children )
148+ ) ;
149+ }
150+
151+ componentDidUpdate = prevProps => {
166152 this . checkImagesLoad ( ) ;
167153 this . props . onReInit && this . props . onReInit ( ) ;
168154 if ( this . props . lazyLoad ) {
@@ -183,6 +169,32 @@ export class InnerSlider extends React.Component {
183169 // this.props.onLazyLoad([leftMostSlide])
184170 // }
185171 this . adaptHeight ( ) ;
172+ let spec = {
173+ listRef : this . list ,
174+ trackRef : this . track ,
175+ ...this . props ,
176+ ...this . state
177+ } ;
178+ const setTrackStyle = this . didPropsChange ( prevProps ) ;
179+ setTrackStyle &&
180+ this . updateState ( spec , setTrackStyle , ( ) => {
181+ if (
182+ this . state . currentSlide >= React . Children . count ( this . props . children )
183+ ) {
184+ this . changeSlide ( {
185+ message : "index" ,
186+ index :
187+ React . Children . count ( this . props . children ) -
188+ this . props . slidesToShow ,
189+ currentSlide : this . state . currentSlide
190+ } ) ;
191+ }
192+ if ( this . props . autoplay ) {
193+ this . autoPlay ( "update" ) ;
194+ } else {
195+ this . pause ( "paused" ) ;
196+ }
197+ } ) ;
186198 } ;
187199 onWindowResized = setTrackStyle => {
188200 if ( this . debouncedResize ) this . debouncedResize . cancel ( ) ;
0 commit comments