react-appear-hook
A React HOC, adding hooks for handling a component enters or exits the viewport.
Add following hooks
- didAppear: Called when a componnet enters the viewport
- didAppearOnce: Same as
didAppear
but called only once - didDisappear: Called when a componnet exits the viewport
- didDisappearOnce: Same as
didDisappear
but called only once
All hooks will receive a param when called: IntersectionObserverEntry
Tip: when react-appear-hook needs to be combined with other decorators or higher-order-components, make sure that react-appear-hook is the innermost (first applied) decorator, this will not affect other HOC behavior, such as MobX observer; otherwise the this
in hooks may not correct.
Installation
npm install react-appear-hook --save
Usage
;; @ state = appeared: false { const appeared = thisstate; return <div> appeared ? 'appeared' : 'disappeared' </div> }