我正在尝试使用useReducer来管理我的应用程序中的状态。我有以下代码:
export interface iState{
records: IHub[];
}
let globalState: iState = {
records: []
}
然后在我的组件中,有这个:
const[state, dispatch ] = useReducer(reducer, globalState);
但是,它在组件的“ globalState”下给了我一条红线,并显示一条消息:
类型“ iState”的参数不能分配给类型“ void”的参数。ts(2345)
What am I doing here? According to this example: https://reactjs.org/docs/hooks-reference.html#usereducer it should work just fine, so is it somethng with TypeScript?
Have your
iState
(i suggest you rename toIState
) extendReducer
喜欢:
Then
const[state, dispatch ] = useReducer<IState<any, any>>(reducer: IState, globalState)