mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 07:02:49 +00:00
18 lines
515 B
TypeScript
18 lines
515 B
TypeScript
import * as React from "react";
|
|
|
|
function usePrevious<T>(value: T) {
|
|
// The ref object is a generic container whose current property is mutable ...
|
|
// ... and can hold any value, similar to an instance property on a class
|
|
const ref = React.useRef<T>(value);
|
|
|
|
// Store current value in ref
|
|
React.useEffect(() => {
|
|
ref.current = value;
|
|
}, [value]); // Only re-run if value changes
|
|
|
|
// Return previous value (happens before update in useEffect above)
|
|
return ref.current;
|
|
}
|
|
|
|
export { usePrevious };
|