diff --git a/.vscode/settings.json b/.vscode/settings.json
index 7aa6142..ac0d179 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,6 +1,7 @@
{
"editor.tabSize": 2,
"editor.formatOnSave": true,
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.tabCompletion": "on",
"[typescript]": {
"editor.codeActionsOnSave": {
diff --git a/packages/react/src/index.tsx b/packages/react/src/index.tsx
index a742cdf..6214ea4 100644
--- a/packages/react/src/index.tsx
+++ b/packages/react/src/index.tsx
@@ -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 {children};
+ return (
+
+ {children}
+
+ );
}
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 ?',
+ if (!ctx.appKey) {
+ console.error(
+ "Aptabase: useAptabase must be used within AptabaseProvider. Did you forget to wrap your app in ?"
);
+ return { trackEvent: () => Promise.resolve() };
}
return { trackEvent };