joshwnj / react-visibility-sensor

Sensor component for React that notifies you when it goes in or out of the window viewport.
MIT License
2.33k stars 195 forks source link

feature request: disable initial visibility check #101

Closed adesurirey closed 6 years ago

adesurirey commented 7 years ago

Great work on this package, thanks a lot.

I have several (like hundreds) visibility sensors in the same view which leads to several performances issues because of the onChange() event that gets fired for all sensors when mounted.

Is there a way to :

This initial check also happens on every active props change.

I've tried a lot of things with no luck :/

adesurirey commented 7 years ago

changing line 101 from :

getInitialState: function () {
    return {
      isVisible: null,
      visibilityRect: {}
    };
  },

to:

getInitialState: function () {
    return {
      isVisible: false,
      visibilityRect: {}
    };
  },

solved my issue. Could we make it an option ? Like by passing an initialVisibility bool prop ?