@leafygreen-ui/hooks
Version:
LeafyGreen UI Kit Custom Hooks
16 lines (12 loc) • 336 B
text/typescript
import { useEffect, useRef } from 'react';
/**
* Hook to store previous props
* https://reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state
*/
export default function usePrevious<T>(value: T): T | undefined {
const ref = useRef<T>();
useEffect(() => {
ref.current = value;
});
return ref.current;
}