Skip to content

Commit 6ab727d

Browse files
committed
🚨 modify context lint
1 parent 66ef3de commit 6ab727d

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/context/index.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@ import io from 'socket.io-client';
33

44
const Context = createContext(null);
55

6-
const initValue = {
6+
interface StateType {
7+
username: string;
8+
uid: string;
9+
socket: any;
10+
messages: [];
11+
onlineUsers: { [key: string]: string };
12+
onlineCount: number;
13+
userhtml: string;
14+
}
15+
16+
const initValue: StateType = {
717
username: '',
818
uid: '',
919
socket: io(),
@@ -51,7 +61,13 @@ const userMessage = (usrMsg: UserMessage, state): object => {
5161
messages: state.messages.concat(usrMsg.message)
5262
};
5363
};
54-
function reducer(state, action) {
64+
interface Payload extends UserMessage, SystemMessage, Login {}
65+
interface ActionType {
66+
type: string;
67+
payload: Payload;
68+
}
69+
70+
const reducer = (state: StateType, action: ActionType): StateType => {
5571
// console.log(state, action);
5672
switch (action.type) {
5773
case 'login':
@@ -63,7 +79,7 @@ function reducer(state, action) {
6379
default:
6480
return state;
6581
}
66-
}
82+
};
6783

6884
const ContextProvider = (props) => {
6985
const [state, dispatch] = useReducer(reducer, initValue);

0 commit comments

Comments
 (0)