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