11 lines
233 B
TypeScript
11 lines
233 B
TypeScript
|
import { useEffect, useRef } from "preact/hooks";
|
||
|
|
||
|
export function usePrevious<T>(value: T): T|undefined {
|
||
|
const ref = useRef();
|
||
|
|
||
|
useEffect(() => {
|
||
|
ref.current = value;
|
||
|
}, [value]);
|
||
|
|
||
|
return ref.current as T|undefined;
|
||
|
}
|