Files
mtdb_movie/common/resources/client/utils/hooks/use-previous.ts
maher 703f50a09d
Some checks failed
Build / run (push) Has been cancelled
first commit
2025-10-29 11:42:25 +01:00

12 lines
330 B
TypeScript
Executable File

import {useEffect, useRef} from 'react';
export function usePrevious<T>(value: T) {
const ref = useRef<T>();
// Store current value in ref
useEffect(() => {
ref.current = value;
}, [value]); // Only re-run if value changes
// Return previous value (happens before update in useEffect above)
return ref.current;
}