gpt4 book ai didi

javascript - createAsyncThunk : Error: addCase cannot be called with two reducers for the same action type

转载 作者:行者123 更新时间:2023-12-05 00:25:07 25 4
gpt4 key购买 nike

当我将操作连接到 时发生此错误额外 reducer
我的代码是

export const fetchCountries = createAsyncThunk(
`country`,
async (organizationId: string) => {

export const saveCountry = createAsyncThunk(
`country`,
async ({ } => {})

const regions = createSlice({
name,
initialState,
reducers: {},
extraReducers: builder => {
builder.addCase(fetchCountries.pending, isFetching);
builder.addCase(fetchCountries.rejected, error);
builder.addCase(fetchCountries.fulfilled, (state, action) => {});

builder.addCase(saveCountry.pending, isFetching);
builder.addCase(saveCountry.rejected, error);
builder.addCase(saveCountry.fulfilled, (state, {payload}) => {});

如果我运行,我会收到此错误: Error: addCase cannot be called with two reducers for the same action type

最佳答案

发生这种情况是因为在我的操作中,很少有具有相同 的 AsyncThunks 操作。类型前缀 .
所以它必须有不同的名称:

export const fetchCountries = createAsyncThunk(
`getCountry`, //<------ this first argument (name) must be unique
async (organizationId: string) => {

export const saveCountry = createAsyncThunk(
`postCountry`,
async ({ } => {})

关于javascript - createAsyncThunk : Error: addCase cannot be called with two reducers for the same action type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68375399/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com