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

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/

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.

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

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.

// COMPLETE SOLUTION

const INCREMENT = ‘INCREMENT’; // define a constant for increment action types

const DECREMENT = ‘DECREMENT’; // define a constant for decrement action types

let defaultState = 0;

const counterReducer = (state = defaultState, action) => {

if(action.type==INCREMENT)

return state + 1;

else if(action.type==DECREMENT)

return state - 1;

else

return state;

}; // define the counter reducer which will increment or decrement the state based on the action it receives

const incAction = () => {

return {type: INCREMENT}

} ; // define an action creator for incrementing

const decAction = () => {

return {type: DECREMENT}

}; // define an action creator for decrementing

const store = Redux.createStore(counterReducer); // define the Redux store here, passing in your reducers