找不到模块:多个减速器时无法解析“ ./减速器”

时间:2019-02-22 14:19:29

标签: javascript reactjs redux

我正在尝试组合减速器

文件夹结构

src
 reducers
  authReducer.js
  lojaReducer.js
  index.js

我正在Index.js导入

import {lojaReducer, authReducer} from './reducers';
import { persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import { combineReducers } from 'redux';

const authPersistConfig = {
  key: 'auth',
  storage: storage,
  blacklist: ['somethingTemporary']
}

export const Reducers = combineReducers ({
  authState: persistReducer(authPersistConfig, authReducer),
  lojaState: lojaReducer
});

但是我遇到了错误

Module not found: Can't resolve './reducers'

当我仅使用lojaReducer时,如何导入多个reducer?

1 个答案:

答案 0 :(得分:2)

由于reducer位于单独的文件中,因此您需要分别导入它们。

类似的东西:

import authReducer from './authReducer'   
import lojaReducer from '. /lojaReducer' 

import { authReducer} from './authReducer'   
import { lojaReducer} from './lojaReducer' 

取决于将它们定义为export还是export default