Reputation: 3284
I'm having the problem above, I tried this, but no luck.
here's my store:
import { compose, combineReducers, applyMiddleware, createStore } from "redux";
import thunkMiddleware from "redux-thunk";
import * as activities from "../reducers/activities";
import * as location from "../reducers/location";
const configureStore = railsProps => {
const composedStore = compose(
applyMiddleware(thunkMiddleware),
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
);
const combinedReducers = combineReducers({
location,
activities
});
return composedStore(createStore)(combinedReducers, railsProps);
};
export default configureStore;
here's my location reducer:
import { combineReducers } from "redux";
import * as actions from "../constants/constants";
const coordinates = (state = {}, action) => {
switch (action.type) {
case actions.GET_LOCATION_SUCCESS:
case actions.GET_LOCATION_REQUEST:
case actions.GET_LOCATION_FAILURE:
default:
return state;
}
};
const reducer = coordinates;
export default reducer;
here's my activities reducer:
import { combineReducers } from "redux";
import * as actions from "../constants/constants";
const page = (state = 0, action) => {
switch (action.type) {
case actions.NEXT_ACTIVITY_PAGE:
return action.page < action.totalPages - 1
? action.page + 1
: action.page;
case actions.PREV_ACTIVITY_PAGE:
return action.page > 0 ? action.page - 1 : 0;
default:
return state;
}
};
const activities = (state = {}, action) => {
switch (action.type) {
case actions.FETCH_ACTIVITIES_SUCCESS: {
return state.concat(action.activities);
}
case actions.FETCH_ACTIVITIES_REQUEST:
case actions.FETCH_ACTIVITIES_FAILURE:
default:
return state;
}
};
const reducer = combineReducers({ page, activities });
export default reducer;
I guess it has something to do with the combineReducers method and how I import stuff, but I'm not sure what's wrong there.
Thanks
Upvotes: 0
Views: 1300
Reputation: 36179
This is wrong:
import * as activities from "../reducers/activities";
import * as location from "../reducers/location";
above would export all the named exports from the file while your reducers are default exports.
correct:
import activities from "../reducers/activities";
import location from "../reducers/location";
EDIT:
if you want to export reducers from the file make them named:
export const page = (state = 0, action) => {
switch (action.type) {
...
}
};
export const activities = (state = {}, action) => {
switch (action.type) {
...
}
};
and later:
import { page, activities } from 'path/to/file.js';
Upvotes: 1