tryemoji / src /util /use-previous.ts
yadongxie's picture
feat: add web
89682f8
raw
history blame contribute delete
223 Bytes
import { useEffect, useRef } from "react";
export function usePrevious<T>(value: T) {
const ref = useRef<T>();
useEffect(() => {
if (value) {
ref.current = value;
}
}, [value]);
return ref.current;
}