我有一个使用useReducer的状态更新程序。我想使其成为一个钩子(强类型)。请指教。
interface IState {
loading: boolean;
name: string;
}
const initialState: IState = {
loading: false,
name: 'Arun'
}
const [state, setState] = useReducer(
(state: IState, newState: Partial < IState > ) => ({
...state,
...newState,
}),
initialState
);
请建议将此函数包装到强类型的挂钩中。
谢谢。