joplin/packages/lib/hooks/usePrevious.ts

14 lines
273 B
TypeScript
Raw Normal View History

import shim from '../shim';
const { useRef, useEffect } = shim.react();
const usePrevious = (value: any, initialValue: any = null) => {
const ref = useRef(initialValue);
useEffect(() => {
ref.current = value;
});
return ref.current;
};
export default usePrevious;