【发布时间】:2021-12-07 07:39:47
【问题描述】:
我正在尝试通过制作待办事项列表来学习 redux
但我遇到了一个错误,我无法解决这个问题
我的类型
export interface TodoType {
text: string;
id: number;
}
export interface TodoState {
todoList: TodoType[];
}
interface ADD_TODO {
type: "ADD_TODO";
payload: TodoType;
}
interface REMOVE_TODO {
type: "REMOVE_TODO";
payload: TodoType;
}
export interface AppState {
todo: TodoState;
}
export type TodoAction = ADD_TODO | REMOVE_TODO;
TodoReducer.ts ;
import { TodoState, TodoAction } from "global";
const INITIAL_STATE: TodoState = {
todoList: [],
};
export const TodoReducer = (state = INITIAL_STATE, action: TodoAction) => {
console.log(state, action);
};
index.ts
import { TodoState } from "global";
import { combineReducers } from "redux";
import { TodoReducer } from "./reducers/TodoReducer";
export interface AppState {
todo: TodoState;
}
const rootReducer = combineReducers<AppState>({
todo: TodoReducer,
});
export default rootReducer;
我的文件的index.ts
import ReactDOM from "react-dom";
import { Provider } from "react-redux";
import { applyMiddleware, createStore } from "redux";
import thunk from "redux-thunk";
import App from "./App";
import rootReducer from "./store";
const store = createStore(rootReducer, applyMiddleware(thunk));
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById("root")
);
如果你能帮我解决这个问题,我会很高兴
【问题讨论】:
标签: reactjs typescript redux dispatch reducers