为什么我的 Redux reducer 在导入时未定义

Why my Redux reducer is undefined when I import it

晚上好,我有个小问题。 我用 React 和 Redux + Redux Toolkit 编写了一个应用程序,只是在将我的减速器导入根减速器时,即 rootReducer,我意识到我的减速器和 unReducer 没有正确导入,这就是问题所在。

我将 rootReducer.js 的范围放在附件中,重点放在有问题的模块上,因此 FormConnexionReducer 相当于我代码中的 unReducer。

预先感谢您的回答。

unReducer.js

//importation des dépendances

const unReducer = createSlice({
  name: 'unReducer',
  initialState: {
    a: '',
    b: '',
  },

  reducers: {
    print_a: () => console.log(a),
    print_b: () => console.log(b)
  },
});

const {print_a, print_b} = unReducer.actions;

export const print_aAction = () =>
  ApplicationStore.dispatch(print_a());

export const print_bAction = () =>
  ApplicationStore.dispatch(print_b());

export default unReducer.reducer;

rootReducer.js


import {combineReducers} from 'redux';
import {default as unReducer} from 'unReducer.js';

export default combineReducers({ // breakpoint, the picture of the scope is at the end of the post
  unReducer,
});

breakpoint scope 点击 LINK 查看图片

您的切片文件似乎引用了一家商店。如果切片引用存储文件,存储文件又引用切片文件,则存在循环依赖。

JavaScript 需要先执行两个文件中的一个 - 从另一个文件导入的文件在那个时间点将是 undefined 并且只会在稍后填充。

确定你的圈子并将一些东西移出到第三个文件中以打破它。