Write a Counter with Redux - expected reducer to be a function

Write a Counter with Redux - expected reducer to be a function
0

#1

Tell us what’s happening:
Keep getting the following error:
Expected the reducer to be a function.

and none of the checkboxes are green even though most of the code should be alright.

Your code so far


const INCREMENT = 'INCREMENT'; // define a constant for increment action types
const DECREMENT = 'DECREMENT'; // define a constant for decrement action types

const counterReducer = (state = initialState, action) => {
  switch(action.type) {
    case INCREMENT:
      return state + 1;
    case DECREMENT:
      return state - 1;
    default:
      return state;
  }
};

const incAction = () => {
  return {type: INCREMENT}
}; // define an action creator for incrementing

const decAction = () => ({type: DECREMENT}); // define an action creator for decrementing

const store = Redux.createStore({
  state : 0,
  reducer: counterReducer
}); // define the Redux store here, passing in your reducers
store.dispatch(incAction);
store.dispatch(decAction);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/redux/write-a-counter-with-redux/


#2

You already have counterReducer function defined.

But you are passing another reducer when creating a store. Just pass in the counterReducer function you created as a parameter.


#3

Could you elaborate on your answer?

const store = Redux.createStore({
  state : 0,
}, counterReducer); // define the Redux store here, passing in 

This does not work either


#4

In your counterreducer function, set state = 0 which is the defualt.

Then, when you are creating the store. Only pass in counterReducer as a parameter.