0.0.2 • Published 4 years ago

react-use-idle v0.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

React hook to track user idle.

Simple, light hook to execute callback during a browser's idle periods.



options

NameTypeDescription
callbackfunctionA reference to a function that should be called in the near future.
idleTimeoutnumberTime in milliseconds to call during the next idle period. Default: 5min (300000ms)
trackEventsarrayList of tracking events. Default: click, keydown, mousedown, mousemove, touchstart, scroll


Example

after component mounted will be start tracking Idle,

import React from 'react';
import useIdle from 'react-use-idle';

const App = () => {
    const idleCallback = () => {
        console.log('idle detected');
    };

    useIdle({ 
        callback: idleCallback,
        idleTimeout: 5000, // 5sec
    });
  
    return (
      <main>
        <h1>...Your App</h1>
      </main>
    )
}