So, there is “an action of type ADD_NOTE”, then we should return action.text - “the text property on the incoming action”. You want to return that from your reducer. Whatever you return from the reducer becomes “the new state”.
I m so lost even with what I started with in Redux. I tried many tutorials on YT but everyone seem to be going so blazing fast. I like to understand with an analogy.
For me, redux is like having a warehouse of information. You cannot go into the warehouse. If you want to change something, you need to fill out a request form (an action object). The request form must have a “type”, saying what type of data manipulation you want. You can also send along data in the request for that you need. To make sure you don’t make a mistake, you can use an action creator, a function that will create your request form (a function that returns a completed action object).
To get the data to the warehouse, you pass your request slip to a magic elf (dispatch function) that takes to it to person in charge of actually making the data change (reducer function). That person reads the “type” on the request slip to know what change to make.
You cannot see the data change directly. You can also call getState. (You can also subscribe listeners, but we may not need to worry about that right now.)
You use an action creator to create an action.
You dispatch the action
Dispatch sends it through the reducer
If the switch statement in the reducer has a case that matches action.type, it will create a new version of state and return it as the new state.
If you call getState, you will see your new state.