Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions packages/gitbook/src/components/Insights/InsightsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type TrackEventCallback = <EventName extends SiteEventName>(
options?: InsightsEventOptions,
) => void;

const InsightsContext = React.createContext<TrackEventCallback | null>(null);
const InsightsContext = React.createContext<TrackEventCallback>(() => {});

interface InsightsProviderProps extends InsightsEventContext {
enabled: boolean;
Expand Down Expand Up @@ -217,12 +217,7 @@ export function InsightsProvider(props: InsightsProviderProps) {
* Get a callback to track an event.
*/
export function useTrackEvent(): TrackEventCallback {
const trackEvent = React.useContext(InsightsContext);
if (!trackEvent) {
throw new Error('useTrackEvent must be used within an InsightsProvider');
}

return trackEvent;
return React.useContext(InsightsContext);
}

/**
Expand Down
Loading