useIdle
Tracks whether the user is being inactive.
Demo
For demonstration purpose, the idle timeout is set to 5s in this demo (default 1min).
Idle: false
Inactive: 0s
Usage
js
import { useIdle } from '@hungpvq/shared-core';
const { idle, lastActive } = useIdle(5 * 60 * 1000); // 5 min
console.log(idle.value); // true or false
Programatically resetting:
js
import { watch } from 'vue';
import { useCounter, useIdle } from '@hungpvq/shared-core';
const { inc, count } = useCounter();
const { idle, lastActive, reset } = useIdle(5 * 60 * 1000); // 5 min
watch(idle, (idleValue) => {
if (idleValue) {
inc();
console.log(`Triggered ${count.value} times`);
reset(); // restarts the idle timer. Does not change lastActive value
}
});