react-use/src/useLatest.ts
2020-07-02 14:19:03 -05:00

10 lines
191 B
TypeScript

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