ragflow / web /src /hooks /commonHooks.ts
balibabu
feat: fetch conversation and delete chat dialog (#69)
058cd84
raw
history blame
755 Bytes
import isEqual from 'lodash/isEqual';
import { useEffect, useRef, useState } from 'react';
export const useSetModalState = () => {
const [visible, setVisible] = useState(false);
const showModal = () => {
setVisible(true);
};
const hideModal = () => {
setVisible(false);
};
return { visible, showModal, hideModal };
};
export const useDeepCompareEffect = (
effect: React.EffectCallback,
deps: React.DependencyList,
) => {
const ref = useRef<React.DependencyList>();
let callback: ReturnType<React.EffectCallback> = () => {};
if (!isEqual(deps, ref.current)) {
callback = effect();
ref.current = deps;
}
useEffect(() => {
return () => {
if (callback) {
callback();
}
};
}, []);
};