@@ -67,9 +67,8 @@ class Sticky extends Component {
6767 }
6868
6969 getTopPosition ( top ) {
70- // TODO, topTarget is for current layout, may remove
7170 // a top argument can be provided to override reading from the props
72- top = top || this . props . top || this . props . topTarget || 0 ;
71+ top = top || this . props . top || 0 ;
7372 if ( typeof top === 'string' ) {
7473 if ( ! this . topTarget ) {
7574 this . topTarget = doc . querySelector ( top ) ;
@@ -282,26 +281,29 @@ class Sticky extends Component {
282281 this . delta = delta ;
283282 }
284283
285- componentWillReceiveProps ( nextProps ) {
286- this . updateInitialDimension ( nextProps ) ;
287- this . update ( ) ;
288- }
289-
290284 componentDidUpdate ( prevProps , prevState ) {
291285 if ( prevState . status !== this . state . status && this . props . onStateChange ) {
292286 this . props . onStateChange ( { status : this . state . status } ) ;
293287 }
294- // if the props for enabling are toggled, then trigger the update or reset depending on the current props
295- if ( prevProps . enabled !== this . props . enabled ) {
296- if ( this . props . enabled ) {
297- this . setState ( { activated : true } , ( ) => {
298- this . updateInitialDimension ( ) ;
299- this . update ( ) ;
300- } ) ;
301- } else {
302- this . setState ( { activated : false } , ( ) => {
303- this . reset ( ) ;
304- } ) ;
288+ const arePropsChanged = ! shallowEqual ( this . props , prevProps ) ;
289+ if ( arePropsChanged ) {
290+ // if the props for enabling are toggled, then trigger the update or reset depending on the current props
291+ if ( prevProps . enabled !== this . props . enabled ) {
292+ if ( this . props . enabled ) {
293+ this . setState ( { activated : true } , ( ) => {
294+ this . updateInitialDimension ( ) ;
295+ this . update ( ) ;
296+ } ) ;
297+ } else {
298+ this . setState ( { activated : false } , ( ) => {
299+ this . reset ( ) ;
300+ } ) ;
301+ }
302+ }
303+ // if the top or bottomBoundary props were changed, then trigger the update
304+ else if ( prevProps . top !== this . props . top || prevProps . bottomBoundary !== this . props . bottomBoundary ) {
305+ this . updateInitialDimension ( ) ;
306+ this . update ( ) ;
305307 }
306308 }
307309 }
0 commit comments