The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/client/hooks/usePolledMethodData.ts

23 lines
548 B

import { useEffect } from 'react';
import { AsyncState } from './useAsyncState';
import { useMethodData } from './useMethodData';
export const usePolledMethodData = <T>(methodName: string, args: any[] = [], intervalMs: number): AsyncState<T> & { reload: () => void } => {
const { reload, ...state } = useMethodData<T>(methodName, args);
useEffect(() => {
const timer = setInterval(() => {
reload();
}, intervalMs);
return (): void => {
clearInterval(timer);
};
}, [reload, intervalMs]);
return {
...state,
reload,
};
};