Felix Felix -3 years ago 117
React JSX Question

reactjs store reducer not correctly implemented

I got in my reactjs app this error:

Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers.


my store looks like this:

import {applyMiddleware, combineReducers, createStore} from "redux";
import thunk from "redux-thunk";

const store = createStore(
combineReducers({}),
applyMiddleware(thunk)
);

export default store;


how should it look like correctly?

Answer Source

You will get this error until you add a reducer to combineReducers see below example.

Counter reducer '/reducers/counter'

export default (state = 0, action) => {
  switch (action.type) {
    case 'INCREMENT':
     return state + 1;
   case 'DECREMENT':
     return state - 1;
   default:
     return state;
  }
};

Store

import {applyMiddleware, combineReducers, createStore} from "redux";
import thunk from "redux-thunk";
import counter from '/reducers/counter';

const store = createStore(
    combineReducers({counter}),
    applyMiddleware(thunk)
);

export default store;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download