main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
949 bytes
|
Rev | Line | |
---|
[d565449] | 1 | "use strict";
|
---|
| 2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 3 | var react_1 = require("react");
|
---|
| 4 | var useIntersection = function (ref, options) {
|
---|
| 5 | var _a = react_1.useState(null), intersectionObserverEntry = _a[0], setIntersectionObserverEntry = _a[1];
|
---|
| 6 | react_1.useEffect(function () {
|
---|
| 7 | if (ref.current && typeof IntersectionObserver === 'function') {
|
---|
| 8 | var handler = function (entries) {
|
---|
| 9 | setIntersectionObserverEntry(entries[0]);
|
---|
| 10 | };
|
---|
| 11 | var observer_1 = new IntersectionObserver(handler, options);
|
---|
| 12 | observer_1.observe(ref.current);
|
---|
| 13 | return function () {
|
---|
| 14 | setIntersectionObserverEntry(null);
|
---|
| 15 | observer_1.disconnect();
|
---|
| 16 | };
|
---|
| 17 | }
|
---|
| 18 | return function () { };
|
---|
| 19 | }, [ref.current, options.threshold, options.root, options.rootMargin]);
|
---|
| 20 | return intersectionObserverEntry;
|
---|
| 21 | };
|
---|
| 22 | exports.default = useIntersection;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.