bigbuffet-rw/app/soapbox/hooks/useRefEventHandler.ts

10 lines
279 B
TypeScript
Raw Normal View History

2022-06-17 15:33:25 -07:00
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;
};