import type { MutableRefObject } from 'react'; import { useRef } from 'react'; /** * Make sure state update into ref * * Useful get latest status without react lifecycle */ export function useUpdateRef(state: T): MutableRefObject { const ref = useRef(state); ref.current = state; return ref; }