Redux 问题 - Store 没有有效的减速器

问题描述 投票:0回答:1

我目前面临 Redux 编码的问题,其中出现以下语句“Store 没有有效的减速器。确保传递给 mergeReducers 的参数是一个值为减速器的对象”。我想与你们团队分享我编写的文件中的代码并触发了问题:

import {configureStore} from '@reduxjs/toolkit'
import rootReducer from './rootReducers'

const store =  configureStore({
    
    reducer: rootReducer,
    middleware: getDefaultMiddleware => {
        return getDefaultMiddleware({
            serializableCheck: false
        })
    },
    devTools: true
})
export default store

import { authReducer } from "./authReducer";

const rootReducer = {

    auth: authReducer,
}
export default rootReducer; 

import { createSlice } from "@reduxjs/toolkit";

export const authReducer = createSlice({
        
    name: 'auth',
    initialState:{
        successMessage: '',
        errorMessage: '',
        loader: false,
        userInfo: ''
    },
    reducers: {

    },
    extraReducers: () => {

    }
})
export default authReducer.reducer

我试图实现浏览器中的 Redux 部分可以显示以下内容:

验证(密码) 成功消息(引脚):“”, 错误消息(引脚):“”, 装载机(引脚):“”, 用户信息(引脚):“”

但是 Redux DevTools 显示未定义(pin)。请从附图中查找问题的证据,我将非常感谢您的回复,以便解决此问题。非常感谢。Redux_error_message

DevTools_undefined

reactjs redux
1个回答
0
投票

问题

auth 缩减器是切片的 default 导出:

export default authReducer.reducer;

所以它也需要被 default 导入。您的代码尝试导入一个不存在的名为

authReducer
的导出。

import { authReducer } from "./authReducer";

解决方案建议

import { authReducer } from "./authReducer";
更新为
import authReducer from "./authReducer";
以正确导入默认导出的 auth reducer。

代码:

import { createSlice } from "@reduxjs/toolkit";

export const authReducer = createSlice({
  name: 'auth',
  initialState:{
    successMessage: '',
    errorMessage: '',
    loader: false,
    userInfo: ''
  },
  reducers: {
    // ...
  },
  extraReducers: () => {
    // ...
  },
});

export default authReducer.reducer;
import authReducer from "./authReducer";

const rootReducer = {
  auth: authReducer,
};

export default rootReducer; 
© www.soinside.com 2019 - 2024. All rights reserved.