LibreChat/client/src/hooks/useTimeout.tsx
Danny Avila 2875380bf1
🔧 fix: URL params, package mismatch, typing, shared link redirect, and o1 (azure) (#4899)
* fix: double decoding of URL params

* fix: prevent streaming options for O1 model (azure)

* fix: update @langchain/openai to version 0.3.14 in package-lock.json

* chore(AuthContext): typing

* chore(useTimeout): typing

* fix: shared link redirecting to login when code block includes "Run Code" button

* fix: typing
2024-12-07 16:55:17 -05:00

39 lines
900 B
TypeScript

import { useEffect, useRef } from 'react';
type TUseTimeoutParams = {
callback: (error: string | number | boolean | null) => void;
delay?: number;
};
type TTimeout = ReturnType<typeof setTimeout> | null;
function useTimeout({ callback, delay = 400 }: TUseTimeoutParams) {
const timeout = useRef<TTimeout>(null);
const callOnTimeout = (value?: string) => {
// Clear existing timeout
if (timeout.current !== null) {
clearTimeout(timeout.current);
}
// Set new timeout
if (value != null && value) {
console.log(value);
timeout.current = setTimeout(() => {
callback(value);
}, delay);
}
};
// Clear timeout when the component unmounts
useEffect(() => {
return () => {
if (timeout.current !== null) {
clearTimeout(timeout.current);
}
};
}, []);
return callOnTimeout;
}
export default useTimeout;