useLatest.ts 192 B

123456789
  1. import { useRef } from 'react'
  2. export const useLatest = <T>(value: T): { readonly current: T } => {
  3. const ref = useRef(value)
  4. ref.current = value
  5. return ref
  6. }
  7. export default useLatest