|
|
@ -15,11 +15,9 @@ function useLatestValue<T>(value: T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Add React.useEvent ?? once the useEvent hook is available
|
|
|
|
// 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>>(
|
|
|
|
function useEvent<F extends (...args: any[]) => any, P extends any[] = Parameters<F>, R = ReturnType<F>>(cb: (...args: P) => R) {
|
|
|
|
cb: (...args: P) => R
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
const cache = useLatestValue(cb);
|
|
|
|
const cache = useLatestValue(cb);
|
|
|
|
return React.useCallback((...args: P) => cache.current(...args), [cache]);
|
|
|
|
return React.useCallback((...args: P) => cache.current(...args), [cache]);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default useEvent;
|
|
|
|
export default useEvent;
|
|
|
|