-
Notifications
You must be signed in to change notification settings - Fork 170
/
UserContext.tsx
45 lines (36 loc) · 1.3 KB
/
UserContext.tsx
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
44
45
import { CometChat } from '@cometchat/chat-sdk-react-native';
import React, { createContext, useState } from 'react';
export const UserContext = createContext<{
user?: CometChat.User,
group?: CometChat.Group,
call?: CometChat.Message,
protectedGroup?: CometChat.Group,
setUser?: (user: CometChat.User)=>void,
setGroup?: (group: CometChat.Group)=>void,
setCall?: (call: CometChat.Message)=>void,
setProtectedGroup?: (group: CometChat.Group)=>void,
}>({});
export const UserContextProvider = (props) => {
const {children} = props;
const [user, assignUser] = useState<CometChat.User>();
const [group, assignGroup] = useState<CometChat.Group>();
const [call, assignCall] = useState<CometChat.Message>();
const [protectedGroup, assignProtectedGroup] = useState<CometChat.Group>();
const setUser = (user: CometChat.User) => {
assignUser(user);
}
const setGroup = (group: CometChat.Group) => {
assignGroup(group);
}
const setProtectedGroup = (group: CometChat.Group) => {
assignProtectedGroup(group);
}
const setCall = (call: CometChat.Message) => {
assignCall(call);
}
return (
<UserContext.Provider value={{user, group, call, protectedGroup, setUser, setGroup, setCall, setProtectedGroup}}>
{children}
</UserContext.Provider>
);
};