mirror of
https://github.com/umami-software/umami.git
synced 2026-02-06 21:57:16 +01:00
21 lines
651 B
TypeScript
21 lines
651 B
TypeScript
import { useTimezone } from 'components/hooks';
|
|
import { REALTIME_INTERVAL } from 'lib/constants';
|
|
import { RealtimeData } from 'lib/types';
|
|
import { useApi } from '../useApi';
|
|
|
|
export function useRealtime(websiteId: string) {
|
|
const { get, useQuery } = useApi();
|
|
const { timezone } = useTimezone();
|
|
const { data, isLoading, error } = useQuery<RealtimeData>({
|
|
queryKey: ['realtime', { websiteId, timezone }],
|
|
queryFn: async () => {
|
|
return get(`/realtime/${websiteId}`, { timezone });
|
|
},
|
|
enabled: !!websiteId,
|
|
refetchInterval: REALTIME_INTERVAL,
|
|
});
|
|
|
|
return { data, isLoading, error };
|
|
}
|
|
|
|
export default useRealtime;
|