@uncinc/uncinc-react-kitchen-sink 2.10.2 → 2.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { MutableRefObject } from 'react';
|
|
2
|
-
export default function useOnScreen(ref: MutableRefObject<HTMLElement
|
|
2
|
+
export default function useOnScreen(ref: MutableRefObject<HTMLElement>, options?: IntersectionObserverInit): boolean;
|
|
@@ -5,7 +5,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
5
5
|
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
6
6
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
7
|
import { useEffect, useState } from 'react';
|
|
8
|
-
export default function useOnScreen(ref) {
|
|
8
|
+
export default function useOnScreen(ref, options) {
|
|
9
9
|
var _useState = useState(false),
|
|
10
10
|
_useState2 = _slicedToArray(_useState, 2),
|
|
11
11
|
isIntersecting = _useState2[0],
|
|
@@ -15,12 +15,18 @@ export default function useOnScreen(ref) {
|
|
|
15
15
|
var _ref2 = _slicedToArray(_ref, 1),
|
|
16
16
|
entry = _ref2[0];
|
|
17
17
|
return setIntersecting(entry.isIntersecting);
|
|
18
|
-
});
|
|
19
|
-
|
|
18
|
+
}, options);
|
|
19
|
+
var currentRef = ref.current;
|
|
20
|
+
if (currentRef) {
|
|
21
|
+
observer.observe(currentRef);
|
|
22
|
+
}
|
|
23
|
+
|
|
20
24
|
// Remove the observer as soon as the component is unmounted
|
|
21
25
|
return function () {
|
|
22
|
-
|
|
26
|
+
if (currentRef) {
|
|
27
|
+
observer.disconnect();
|
|
28
|
+
}
|
|
23
29
|
};
|
|
24
|
-
}, [ref]);
|
|
30
|
+
}, [options, ref]);
|
|
25
31
|
return isIntersecting;
|
|
26
32
|
}
|