Improve useThrottleFn type definition

This commit is contained in:
Rogdham 2019-09-03 16:14:28 +02:00
parent e88f0ceb8a
commit 664b071d2d

View File

@ -1,7 +1,7 @@
import { useEffect, useRef, useState } from 'react';
import useUnmount from './useUnmount';
const useThrottleFn = <T>(fn: (...args: any[]) => T, ms: number = 200, args: any[]) => {
const useThrottleFn = <T, U extends any[]>(fn: (...args: U) => T, ms: number = 200, args: U) => {
const [state, setState] = useState<T>(null as any);
const timeout = useRef<ReturnType<typeof setTimeout>>();
const nextArgs = useRef(null) as any;