Skip to content

Commit

Permalink
[@mantine/hooks] use-idle: Improve types for events (#2704)
Browse files Browse the repository at this point in the history
  • Loading branch information
arimariojesus committed Oct 22, 2022
1 parent 2599b47 commit 15405e8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/mantine-hooks/src/use-idle/use-idle.ts
@@ -1,14 +1,20 @@
import { useState, useEffect, useRef } from 'react';

const DEFAULT_EVENTS = ['keypress', 'mousemove', 'touchmove', 'click', 'scroll'];
const DEFAULT_EVENTS: (keyof DocumentEventMap)[] = [
'keypress',
'mousemove',
'touchmove',
'click',
'scroll',
];
const DEFAULT_OPTIONS = {
events: DEFAULT_EVENTS,
initialState: true,
};

export function useIdle(
timeout: number,
options?: Partial<{ events: string[]; initialState: boolean }>
options?: Partial<{ events: (keyof DocumentEventMap)[]; initialState: boolean }>
) {
const { events, initialState } = { ...DEFAULT_OPTIONS, ...options };
const [idle, setIdle] = useState<boolean>(initialState);
Expand Down

0 comments on commit 15405e8

Please sign in to comment.