How does notesReducer refers to the addNoteText here

Tell us what’s happening:

I’m a bit confused how does notesReducer refers to the elements from the addNoteText function? We are not passing addNoteText as a callback function anywhere among notesReducer 's arguments, so how does it retrieve text out of the addNoteText ?

Your code so far


const ADD_NOTE = 'ADD_NOTE';

const notesReducer = (state = 'Initial State', action) => {
switch(action.type) {
  // change code below this line
  case ADD_NOTE:
    return action.text;
  // change code above this line
  default:
    return state;
}
};

const addNoteText = (note) => {
// change code below this line
return {
  type: ADD_NOTE,
  text: note
};
// change code above this line
};

const store = Redux.createStore(notesReducer);

console.log(store.getState());
store.dispatch(addNoteText('Hello!'));
console.log(store.getState());

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36.

Challenge: Send Action Data to the Store

Link to the challenge:

addNoteText returns action that store will pass to reducer along with the current state

1 Like