-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathuseAppKitContext.ts
More file actions
43 lines (37 loc) · 1.24 KB
/
useAppKitContext.ts
File metadata and controls
43 lines (37 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { useContext } from 'react';
import { AppKitContext, type AppKitContextType } from '../AppKitContext';
/**
* Hook to access the AppKit context
*
* @remarks
* This is an internal hook used by other AppKit hooks to ensure they're used within
* the AppKitProvider. You typically don't need to use this hook directly - use the
* higher-level hooks like `useAppKit`, `useAccount`, `useAppKitTheme`, etc. instead.
*
* @returns {AppKitContextType} The AppKit context containing the AppKit instance
*
* @throws {Error} If used outside of an AppKitProvider
* @throws {Error} If the AppKit instance is not yet available in context
*
* @internal
*
* @example
* ```tsx
* // This is typically used internally by other hooks
* function MyCustomHook() {
* const context = useAppKitContext();
* // Use context.appKit...
* }
* ```
*/
export const useAppKitContext = (): AppKitContextType => {
const context = useContext(AppKitContext);
if (context === undefined) {
throw new Error('useAppKit must be used within an AppKitProvider');
}
if (!context.appKit) {
// This might happen if the provider is rendered before AppKit is initialized
throw new Error('AppKit instance is not yet available in context.');
}
return context;
};