@binaryoperations/json-schema-form
Version:
18 lines (11 loc) • 355 B
text/typescript
import { useLayoutEffect } from 'react';
import { useRef } from "./useRef";
export const usePrevious = <T>(value: T) => {
const ref = useRef<T>(value);
// this hook runs before any use effect, so set the previous value.
useLayoutEffect(() => {
ref.current = value;
}, [value]);
return ref;
};
export default usePrevious;