我正在遵循react-redux的this个教程,但我卡住了.
当我try 设置为configureStore
时,出现错误Property 'reducer' does not exist on type 'Reducer<Winner>'
store 是这样的:
store.ts
import { configureStore } from "@reduxjs/toolkit";
import winnerSlice from "./winnerSlice";
const store = configureStore({
reducer: {
winners: winnerSlice.reducer,
}
})
export type RootState = ReturnType<typeof store.getState>
export type AppDispatch = typeof store.dispatch
export type AppStore = typeof store
下面是winnerSlice.ts:
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { RootState } from './store';
interface Winner {
name: string
}
const initialState: Winner = {
name: "",
}
export const winnerSlice = createSlice({
name: 'winner',
initialState,
reducers: {
setWinner: (state, action: PayloadAction<string>) => {
state.name = action.payload
},
clearWinner: (state) => {
state.name = ""
}
}
})
export const { setWinner, clearWinner } = winnerSlice.actions
export const selectWinner = (state: RootState) => state.winners.value // This line is also erroneous by the way
export default winnerSlice.reducer
我需要一个关于如何配置store 的提示.文档中的示例是不完整的.这些都没有定义,所以我被困住了:
posts: postsReducer,
comments: commentsReducer,
users: usersReducer,