【发布时间】:2021-10-05 13:04:49
【问题描述】:
您好,我正在尝试学习 useReducer 以便在将来使用它,但我遇到了一个错误。 当我尝试初始化它时,我无法传递初始状态
这是我的代码:
const initialState = {
count: 0,
};
const reducer = () => {
console.log('hello');
};
const Test = (): ReactElement => {
const [state, dispatch] = useReducer(reducer, initialState);
return <div>test</div>;
};
我在 initialState 上收到错误提示:
Argument of type '{ count: number; }' is not assignable to parameter of type 'void'
我确切地说我使用打字稿
【问题讨论】:
标签: reactjs typescript react-hooks