File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,8 @@ export class InView extends React.Component<
5050 if (
5151 prevProps . rootMargin !== this . props . rootMargin ||
5252 prevProps . root !== this . props . root ||
53- prevProps . threshold !== this . props . threshold
53+ prevProps . threshold !== this . props . threshold ||
54+ prevProps . skip !== this . props . skip
5455 ) {
5556 unobserve ( this . node )
5657 this . observeNode ( )
@@ -86,7 +87,7 @@ export class InView extends React.Component<
8687 handleNode = ( node ?: Element | null ) => {
8788 if ( this . node ) {
8889 unobserve ( this . node )
89- if ( ! node && ! this . props . triggerOnce ) {
90+ if ( ! node && ! this . props . triggerOnce && ! this . props . skip ) {
9091 this . setState ( { inView : false , entry : undefined } )
9192 }
9293 }
Original file line number Diff line number Diff line change @@ -83,6 +83,25 @@ it('Should respect skip', () => {
8383 expect ( observe ) . not . toHaveBeenCalled ( )
8484} )
8585
86+ it ( 'Should not trigger onChange whenn skipping' , ( ) => {
87+ observe . mockImplementation ( ( el , callback , options ) => {
88+ callback ( true , { } )
89+ } )
90+ const onChange = jest . fn ( )
91+ const { rerender } = render (
92+ < Observer onChange = { onChange } > { plainChild } </ Observer > ,
93+ )
94+ expect ( onChange ) . toHaveBeenCalledTimes ( 1 )
95+
96+ rerender (
97+ < Observer skip onChange = { onChange } >
98+ { plainChild }
99+ </ Observer > ,
100+ )
101+ expect ( onChange ) . toHaveBeenCalledTimes ( 1 )
102+ expect ( unobserve ) . toHaveBeenCalled ( )
103+ } )
104+
86105it ( 'Should unobserve old node' , ( ) => {
87106 const { rerender, container } = render (
88107 < Observer >
You can’t perform that action at this time.
0 commit comments