我是Redux的新手,我正在尝试集成一个基本版本,以获得一个可靠的构建平台。我的基本设置基于Super Simple React-Redux Setup
我确实将它拆分为三个文件,但由于某种原因,它会在createStore函数中返回上面提到的错误。
export const increment= state => ({
type: "INCREMENT",
state
})
import {combineReducers} from 'redux';
import increment from './actions';
export const myFunctions= (state= {}, action)=>{
switch(action.type){
case "INCREMENT":
state.value += 1;
default:
return state;
}
return state;
}
export const reducers = combineReducers({
myFunctions
});
import { createStore, compose} from 'redux';
import reducers from './reducer.js';
export function configureStore(initialState = {value: 1}) {
const store = createStore(reducers, initialState);
return store;
};
export const store = configureStore();
我只是有点好奇为什么这是hapening,有什么荒谬的明显,我在这里失踪?
答案 0 :(得分:1)
您的reducer文件没有默认导出,这意味着当您在商店中导入文件时,它将是未定义的。
将reducer.js更新为以下
reducer.js
import {combineReducers} from 'redux';
import increment from './actions';
const myFunctions= (state= {}, action)=>{
switch(action.type){
case "INCREMENT":
state.value += 1;
default:
return state;
}
return state;
}
const reducers = combineReducers({
myFunctions
});
export default reducers;