import { useRef } from 'react'; interface Latest { readonly current: T; } export const useLatest = (value: T): Latest => { const ref = useRef(value); ref.current = value; return ref; };