File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,17 @@ import io from 'socket.io-client';
33
44const 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
6884const ContextProvider = ( props ) => {
6985 const [ state , dispatch ] = useReducer ( reducer , initValue ) ;
You can’t perform that action at this time.
0 commit comments