Skip to content

Commit

Permalink
fix(useRetimer): improve timerId typing
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle1an committed Jan 1, 2025
1 parent b597636 commit 24a54a1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/use-retimer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import 'client-only';

import { useCallback, useRef } from 'react';

type Timer = number | ReturnType<typeof setTimeout>;

/** @see https://foxact.skk.moe/use-retimer */
export function useRetimer() {
const timerIdRef = useRef<number>();
const timerIdRef = useRef<Timer>();

return useCallback((timerId?: number | ReturnType<typeof setTimeout>) => {
return useCallback((timerId?: Timer) => {
if (typeof timerIdRef.current === 'number') {
clearTimeout(timerIdRef.current);
}
Expand Down

0 comments on commit 24a54a1

Please sign in to comment.