Team Disco
- Dylan Roberts
- James Viall
Typing the useState React hook
| export function useAsyncDebounce<T extends (args: any[]) => any>(defaultFn: T, defaultWait: number): T { | |
| const debounceRef = React.useRef<{ | |
| promise?: Promise<T>, | |
| resolve?: (value: T | PromiseLike<T>) => void, | |
| reject?: (reason?: any) => void, | |
| timeout?: NodeJS.Timeout | |
| }>({}) | |
| // the given args could be props, which change, so we want to always use latest definitions. | |
| const getDefaultFn = useGetLatest(defaultFn) |