A library to check the status of the user and to run a callback when its considered Idle.
Install the library via npm install user-idle-tracker
or yarn add user-idle-tracker
. Or you can even download the file here and load with the good and old way <script src="user-idle-tracker.min.js"></script>
.
If you used npm/yarn, just import the file:
import UserIdleTracker from "user-idle-tracker";
And now you can use it like:
function callback() {
console.log("A function to be called when user is considered idle");
}
const idleTime = 1000; // time in milliseconds defined to be considered idle
const tracker = new UserIdleTracker(callback, idleTime);
You can see the tests on index.test.js, use yarn test
to run the tests. If you want to see an example working on the Browser, just run yarn start
.