useUpdatedRef.ts.

Returns a ref that always contains the latest value specified as parameter.

import * as React from 'https://unpkg.com/react@18/umd/react.production.min.js';
const { useRef } = React;

export function useUpdatedRef<T>(value: T) {
  const ref = useRef<T>(value);
  ref.current = value;
  return ref;
}