export const productDetailSlice = createSlice({
name: "productDetail",
initialState,
reducers: {
},
extraReducers: {
[getProductDetail.pending.type]: (state) => {
// return {...state, loading: true}
state.loading = true
},
[getProductDetail.fulfilled.type]: (state, action) => {
state.loading = false
state.data = action.payload
state.error = null
},
[getProductDetail.rejected.type]: (state, action: PayloadAction<string | null>) => {
state.loading = false
state.error = action.payload
}
},
})
上面代码extraReducers报错,我进入extraReducers的定义,看到是其是一个函数:
// 文件:node_modules/@reduxjs/toolkit/dist/createSlice.d.ts
extraReducers?: (builder: ActionReducerMapBuilder<State>) => void;
/**
* A map of selectors that receive the slice's state and any additional arguments, and return a result.
*/
selectors?: Selectors;
}
我的tkt版本: “redux-toolkit”: “^1.1.2”
React18 精讲 + 结合 TS 实战 + 热门业务开发,获取必备技能
了解课程