@supunlakmal/hooks
Version:
A collection of reusable React hooks
13 lines • 465 B
JavaScript
import { useEffect, useRef } from 'react';
export const usePreviousDifferent = (value) => {
const previousRef = useRef(undefined);
const previousDifferentRef = useRef(undefined);
useEffect(() => {
if (previousRef.current !== value) {
previousDifferentRef.current = previousRef.current;
}
previousRef.current = value;
});
return previousDifferentRef.current;
};
//# sourceMappingURL=usePreviousDifferent.js.map