javascript - createAsyncThunk: 错误: addCase 不能用两个 reducer 调用相同的操作类型
问题描述
当我将操作连接到extraReducers时发生此错误 我的代码是
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
解决方案
发生这种情况是因为在我的操作中几乎没有具有相同typePrefix的AsyncThunks操作。
所以它必须有不同的名称:
export const fetchCountries = createAsyncThunk(
`country/get`, //<------ this first argument (typePrefix) must be unique
async (organizationId: string) => {
export const saveCountry = createAsyncThunk(
`country/post`,
async ({ } => {})
推荐阅读
- java - hackerrank:与 Dijkstra 算法相关的问题超过了时间限制
- java - Play Framework - 如何使用多个 MySQL 查询构建网页
- c# - Unity 以 100% 打印出 CPU 使用率
- reactjs - 在 React 中返回 JSZip 压缩文件
- java - 与元素类型“null”关联的属性“standardData”的值不能包含“<”字符
- python - Python - 尝试从 Pandas 中的 DataFrame 中随机选择一个元素
- c# - 为什么当我插入文本框 C# 时不显示 MDI 子窗体
- javascript - 如何在使用 Java Script 将 JSON 导出到 Excel 时将整列设为数字
- r - 如何根据条件更改数据框中列的多个行值?
- python - 连续增加一个值,如果日期更改,则将变量设置为零