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