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;
      return state;

const store = Redux.createStore(reducer);

// Global count variable:
let count = 0;

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

// Change code above this line

store.dispatch({type: ADD});
store.dispatch({type: ADD});
store.dispatch({type: ADD});

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ 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++

You just need to pass incrementCount as the argument to subscribe. Instead, you are passing the execution of incrementCount to subscribe. The subscribe method will execute the function on its own. You want to pass a function that will be “called” later by subscribe.

1 Like

Ah! Thanks for clarifying :grinning: