mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
20 lines
583 B
TypeScript
20 lines
583 B
TypeScript
'use client';
|
|
import { createContext, ReactNode } from 'react';
|
|
import { usePixelQuery } from '@/components/hooks';
|
|
import { Loading } from '@umami/react-zen';
|
|
|
|
export const PixelContext = createContext(null);
|
|
|
|
export function PixelProvider({ pixelId, children }: { pixelId?: string; children: ReactNode }) {
|
|
const { data: pixel, isLoading, isFetching } = usePixelQuery(pixelId);
|
|
|
|
if (isFetching && isLoading) {
|
|
return <Loading position="page" />;
|
|
}
|
|
|
|
if (!pixel) {
|
|
return null;
|
|
}
|
|
|
|
return <PixelContext.Provider value={pixel}>{children}</PixelContext.Provider>;
|
|
}
|