diff --git a/packages/gitbook/src/components/Insights/InsightsProvider.tsx b/packages/gitbook/src/components/Insights/InsightsProvider.tsx index f26b88b5c..bfa80e0e3 100644 --- a/packages/gitbook/src/components/Insights/InsightsProvider.tsx +++ b/packages/gitbook/src/components/Insights/InsightsProvider.tsx @@ -59,7 +59,7 @@ type TrackEventCallback = ( options?: InsightsEventOptions, ) => void; -const InsightsContext = React.createContext(null); +const InsightsContext = React.createContext(() => {}); interface InsightsProviderProps extends InsightsEventContext { enabled: boolean; @@ -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); } /**