我正在学习redux。我不明白在../reducers/index.js文件中我可以导入一个reducer,在这种情况下它被称为“SearchReducer”。但是如果我查看调用它的文件,那里使用的函数不会被称为“SearchReducer”,它只是“导出默认函数”等等。我可以在导入时基本上将reducer命名为index.js中的任何内容吗?
这是../reducers / index.js
import { combineReducers } from 'redux';
import SearchReducer from './reducer_search';
import { reducer as formReducer } from 'redux-form';
const rootReducer = combineReducers({
search: SearchReducer,
});
export default rootReducer;
这是../reducers / reducer_search.js
import { SEARCH_USER } from '../actions/index';
export default function(state = [], action) {
switch(action.type) {
case SEARCH_USER:
return [ action.payload.data ];
}
return state;
}
答案 0 :(得分:3)
将组件导出为默认设置时,您可以按任意名称导入该组件,但是当您将其导出为named export
时,需要在{}
中使用相同名称导入该组件,然后您可以重命名就像在
import { reducer as formReducer } from 'redux-form';