bigbuffet-rw/app/soapbox/hooks/useRefEventHandler.ts
2022-06-17 17:33:25 -05:00

9 lines
279 B
TypeScript

import { useRef } from 'react';
/** Hook that allows using useState values in event handlers. */
// https://stackoverflow.com/a/64770671/8811886
export const useRefEventHandler = (fn: (...params: any) => void) => {
const ref = useRef(fn);
ref.current = fn;
return ref;
};