You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/6/en/part6a.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,7 +79,9 @@ Let's change the code a bit. We have used if-else statements to respond to an ac
79
79
Let's also define a [default value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters) of 0 for the parameter <i>state</i>. Now the reducer works even if the store state has not been primed yet.
Reducer is never supposed to be called directly from the application's code. Reducer is only given as a parameter to the _createStore_-function which creates the store:
97
99
98
100
```js
101
+
// highlight-start
99
102
import { createStore } from'redux'
103
+
// highlight-end
100
104
101
105
constcounterReducer= (state=0, action) => {
102
106
// ...
103
107
}
104
108
109
+
// highlight-start
105
110
conststore=createStore(counterReducer)
111
+
// highlight-end
106
112
```
107
113
108
114
The store now uses the reducer to handle <i>actions</i>, which are <i>dispatched</i> or 'sent' to the store with its [dispatch](https://redux.js.org/api/store#dispatchaction) method.
@@ -354,7 +360,9 @@ We added a new note to the state with the method _state.push(action.payload)_ wh
354
360
```js
355
361
constnoteReducer= (state= [], action) => {
356
362
if (action.type==='NEW_NOTE') {
363
+
// highlight-start
357
364
returnstate.concat(action.payload)
365
+
// highlight-stop
358
366
}
359
367
360
368
return state
@@ -572,7 +580,9 @@ Adding a new note creates the state it returns with Array's _concat_ function. L
572
580
constnoteReducer= (state= [], action) => {
573
581
switch(action.type) {
574
582
case'NEW_NOTE':
583
+
// highlight-start
575
584
return [...state, action.payload]
585
+
// highlight-stop
576
586
case'TOGGLE_IMPORTANCE':
577
587
// ...
578
588
default:
@@ -743,8 +753,10 @@ Your application can have a modest appearance, nothing else is needed but button
743
753
Let's add the functionality for adding new notes and changing their importance:
0 commit comments