11
common/resources/client/utils/hooks/use-previous.ts
Executable file
11
common/resources/client/utils/hooks/use-previous.ts
Executable file
@@ -0,0 +1,11 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user