import { useRef, MutableRefObject } from 'react'; export function useUpdateRef(state: T): MutableRefObject { const ref = useRef(state); ref.current = state; return ref; }