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

28 lines
626 B

import { useEffect } from 'react';
import { ServerMethods } from '../contexts/ServerContext';
import { AsyncState } from './useAsyncState';
import { useMethodData } from './useMethodData';
export const usePolledMethodData = <T>(
methodName: keyof ServerMethods,
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,
};
};