forked from Vero-protocol/vero-guardian-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSocketIOContext.tsx
More file actions
31 lines (26 loc) · 732 Bytes
/
Copy pathSocketIOContext.tsx
File metadata and controls
31 lines (26 loc) · 732 Bytes
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
'use client';
import {
createContext,
useContext,
type ReactNode,
} from 'react';
import { useSocketIO, type UseSocketIOResult } from '@/hooks/useSocketIO';
const SocketIOContext = createContext<UseSocketIOResult | null>(null);
export function SocketIOProvider({ children }: { children: ReactNode }) {
const socket = useSocketIO({
autoConnect: true,
invalidateOnEvent: true,
});
return (
<SocketIOContext.Provider value={socket}>
{children}
</SocketIOContext.Provider>
);
}
export function useSocketIOContext(): UseSocketIOResult {
const ctx = useContext(SocketIOContext);
if (!ctx) {
throw new Error('useSocketIOContext must be used within a SocketIOProvider');
}
return ctx;
}