-
Notifications
You must be signed in to change notification settings - Fork 374
Expand file tree
/
Copy pathAppContext.tsx
More file actions
32 lines (28 loc) · 1 KB
/
AppContext.tsx
File metadata and controls
32 lines (28 loc) · 1 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
import React, { PropsWithChildren, createContext, useState } from 'react';
import { Channel as ChannelType } from 'stream-chat';
import { ThreadContextValue } from 'stream-chat-expo';
export type AppContextType = {
channel: ChannelType | undefined;
setChannel: React.Dispatch<React.SetStateAction<ChannelType | undefined>>;
setThread: React.Dispatch<
React.SetStateAction<ThreadContextValue['thread'] | undefined>
>;
thread: ThreadContextValue['thread'] | undefined;
};
export const AppContext = createContext<AppContextType>({
channel: undefined,
setChannel: undefined,
setThread: undefined,
thread: undefined,
});
export const AppProvider = ({ children }: PropsWithChildren) => {
const [channel, setChannel] = useState<ChannelType | undefined>(undefined);
const [thread, setThread] = useState<
ThreadContextValue['thread'] | undefined
>(undefined);
return (
<AppContext.Provider value={{ channel, setChannel, thread, setThread }}>
{children}
</AppContext.Provider>
);
};