useIdle
跟踪页面上的用户是否处于空闲状态。
Usage
实时编辑器
function Demo() { const isIdle = useIdle(3e3); return ( <div> <div>User is idle: {isIdle ? "Yes 😴" : "Nope"}</div> </div> ); };
结果
Loading...
API
UseIdle
Returns
boolean
: 是否处于空闲
Arguments
参数名 | 描述 | 类型 | 默认值 |
---|---|---|---|
ms | 检测时间 | number | undefined | 60e3 |
initialState | 初始值 | boolean | undefined | false |
events | 监听的事件 | (keyof WindowEventMap)[] | undefined | ["mousemove","mousedown","resize","keydown","touchstart","wheel"] |