don't throw error
This commit is contained in:
parent
4966ef28ec
commit
b1062af145
2 changed files with 13 additions and 7 deletions
|
@ -1,7 +1,7 @@
|
|||
'use client';
|
||||
"use client";
|
||||
|
||||
import { init, trackEvent, type AptabaseOptions } from '@aptabase/web';
|
||||
import { createContext, useContext, useEffect } from 'react';
|
||||
import { init, trackEvent, type AptabaseOptions } from "@aptabase/web";
|
||||
import { createContext, useContext, useEffect } from "react";
|
||||
|
||||
globalThis.__APTABASE_SDK_VERSION__ = `aptabase-react@${process.env.PKG_VERSION}`;
|
||||
|
||||
|
@ -27,15 +27,20 @@ export function AptabaseProvider({ appKey, options, children }: Props) {
|
|||
init(appKey, options);
|
||||
}, [appKey, options]);
|
||||
|
||||
return <AptabaseContext.Provider value={{ appKey, options }}>{children}</AptabaseContext.Provider>;
|
||||
return (
|
||||
<AptabaseContext.Provider value={{ appKey, options }}>
|
||||
{children}
|
||||
</AptabaseContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useAptabase(): AptabaseClient {
|
||||
const ctx = useContext(AptabaseContext);
|
||||
if (!ctx) {
|
||||
throw new Error(
|
||||
'useAptabase must be used within AptabaseProvider. Did you forget to wrap your app in <AptabaseProvider>?',
|
||||
if (!ctx.appKey) {
|
||||
console.error(
|
||||
"Aptabase: useAptabase must be used within AptabaseProvider. Did you forget to wrap your app in <AptabaseProvider>?"
|
||||
);
|
||||
return { trackEvent: () => Promise.resolve() };
|
||||
}
|
||||
|
||||
return { trackEvent };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue