0.4.0 • Published 2 years ago

@chancellor-arthur/react-document-visibility v0.4.0

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

@chancellor-arthur/react-document-visibility

Implemented react hook, which

will tell if the browser tab is active (visible) now
will tell you how many times since the component was initialized the tab has become inactive (invisible)
will provide a function in which you can subscribe to a change in the activity (visibility) of the current tab

Hook example

import React, {useEffect} from 'react';
import {useDocumentVisibility} from "@chancellor-arthur/react-document-visibility";

const LeaveTabCounter = () => {
const {count, visible, onVisibilityChange} = useDocumentVisibility();

useEffect(() => {
    onVisibilityChange((isVisible: boolean) => {
        console.log('first handler', isVisible);
    });
    onVisibilityChange((isVisible: boolean) => {
        console.log('second handler', isVisible);
    });
}, []);

return (
    <div>
  <span>
    Вы покинули страницу: {count} раз
    Вкладка активна? {visible ? 'да' : 'нет'}
  </span>
    </div>
    );
};

export default LeaveTabCounter;
0.4.0

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago