Files
cinny/src/app/hooks/usePreviousValue.ts
T

12 lines
271 B
TypeScript
Raw Normal View History

2024-07-08 16:57:10 +05:30
import { useEffect, useRef } from 'react';
export const usePreviousValue = <T>(currentValue: T, initialValue: T) => {
const valueRef = useRef(initialValue);
useEffect(() => {
valueRef.current = currentValue;
}, [currentValue]);
return valueRef.current;
};