-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathprovider.tsx
More file actions
40 lines (37 loc) · 990 Bytes
/
provider.tsx
File metadata and controls
40 lines (37 loc) · 990 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
32
33
34
35
36
37
38
39
40
/**
* RealtimeProvider — wraps your React app to provide a RealtimeClient.
*
* @example
* ```tsx
* import { RealtimeClient } from '@constructive-io/realtime';
* import { RealtimeProvider } from '@constructive-io/react-realtime';
*
* const realtime = new RealtimeClient({
* url: 'wss://api.example.com/graphql',
* getToken: () => authStore.getToken(),
* });
*
* function App() {
* return (
* <RealtimeProvider client={realtime}>
* <MyApp />
* </RealtimeProvider>
* );
* }
* ```
*/
import type { ReactNode } from 'react';
import React from 'react';
import type { RealtimeClient } from '@constructive-io/realtime';
import { RealtimeContext } from './context';
export interface RealtimeProviderProps {
client: RealtimeClient;
children: ReactNode;
}
export function RealtimeProvider({ client, children }: RealtimeProviderProps) {
return (
<RealtimeContext.Provider value={client}>
{children}
</RealtimeContext.Provider>
);
}