infinity-forge
Version:
32 lines • 1.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useIsVisible = useIsVisible;
var react_1 = require("react");
function useIsVisible(_a) {
var ref = _a.ref, showOneTime = _a.showOneTime;
var _b = (0, react_1.useState)(false), isIntersecting = _b[0], setIntersecting = _b[1];
(0, react_1.useEffect)(function () {
var observer = new IntersectionObserver(function (_a) {
var entry = _a[0];
if (showOneTime) {
// Se o showOneTime for verdadeiro e o estado já estiver como visível, não o altere mais
if (entry.isIntersecting) {
setIntersecting(true);
observer.disconnect(); // Desconecta após a primeira interseção
}
}
else {
// Para comportamento normal, sem showOneTime
setIntersecting(entry.isIntersecting);
}
});
if (ref.current) {
observer.observe(ref.current);
}
return function () {
observer.disconnect();
};
}, [ref, showOneTime]);
return isIntersecting;
}
//# sourceMappingURL=index.js.map