d146b78a97
This reverts commit 0276231c31.
14 lines
435 B
TypeScript
14 lines
435 B
TypeScript
import React from 'react'
|
|
import { useLatestValue } from './use-latest-value'
|
|
|
|
export let useEvent =
|
|
// TODO: Add React.useEvent ?? once the useEvent hook is available
|
|
function useEvent<
|
|
F extends (...args: any[]) => any,
|
|
P extends any[] = Parameters<F>,
|
|
R = ReturnType<F>
|
|
>(cb: (...args: P) => R) {
|
|
let cache = useLatestValue(cb)
|
|
return React.useCallback((...args: P) => cache.current(...args), [cache])
|
|
}
|