import { useDocumentVisibility } from "@kalabass/react-use-document-visibility";
import { FC, useEffect } from "react";
const DocumentVisibility: FC = () => {
const { count, visible, onVisibilityChange } = useDocumentVisibility();
useEffect(() => {
const unsubscribeFirstHandler = onVisibilityChange(isVisible => {
console.log("first handler", isVisible);
});
const unsubscribeSecondHandler = onVisibilityChange(isVisible => {
console.log("second handler", isVisible);
});
const timerId = setTimeout(() => unsubscribeSecondHandler(), 5000);
return () => {
unsubscribeFirstHandler();
unsubscribeSecondHandler();
clearTimeout(timerId);
};
}, [onVisibilityChange]);
return (
<div>
<span>
Вы покинули страницу: {count} раз Вкладка активна?{" "}
{visible ? "да" : "нет"}
</span>
</div>
);
};
export default DocumentVisibility;
@kalabass/react-use-document-visibility
1.3.8 • Public • PublishedReadme
Keywords
nonePackage Sidebar
Install
npm i @kalabass/react-use-document-visibility
Weekly Downloads
0
Version
1.3.8
License
none
Unpacked Size
5.26 kB
Total Files
9