Redux - Register a Store Listener

Tell us what’s happening:
I successfully pass the tests with my code as-is, but nothing is being logged to the console. After running my tests, the log output shows “Build error, open your browser console to learn more.” I opened the browser console and the only thing that stands out is this (img attached). Is there something wrong with my implementation?

Your code so far

const ADD = 'ADD';

const reducer = (state = 0, action) => {
  switch(action.type) {
    case ADD:
      return state + 1;
    default:
      return state;
  }
};

const store = Redux.createStore(reducer);

// Global count variable:
let count = 0;

// Change code below this line
function incrementCount() {
  return count++;
};

store.subscribe(incrementCount());
// Change code above this line

store.dispatch({type: ADD});
console.log(count);
store.dispatch({type: ADD});
console.log(count);
store.dispatch({type: ADD});
console.log(count);

Your browser information:

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

Challenge: Redux - Register a Store Listener

Link to the challenge:

store.subscribe takes a callback, you should not be invoking incrementCount

I’m confused why subscribe(incrementCount()); is not considered to use a callback?

I do need the incrementCount() function, right? Or should I instead be doing something like this:

subscribe(incrementCount()=> {
  return count++
})

Ah! Thanks for clarifying :grinning:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.