Skip to content

Commit 19b734d

Browse files
authored
Merge pull request #3308 from patchamama/patch-5
Update part6a.md
2 parents 1e7548b + 53f3581 commit 19b734d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/content/6/en/part6a.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ Let's change the code a bit. We have used if-else statements to respond to an ac
7979
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.
8080

8181
```js
82+
// highlight-start
8283
const counterReducer = (state = 0, action) => {
84+
// highlight-end
8385
switch (action.type) {
8486
case 'INCREMENT':
8587
return state + 1
@@ -96,13 +98,17 @@ const counterReducer = (state = 0, action) => {
9698
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:
9799

98100
```js
101+
// highlight-start
99102
import { createStore } from 'redux'
103+
// highlight-end
100104

101105
const counterReducer = (state = 0, action) => {
102106
// ...
103107
}
104108

109+
// highlight-start
105110
const store = createStore(counterReducer)
111+
// highlight-end
106112
```
107113

108114
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
354360
```js
355361
const noteReducer = (state = [], action) => {
356362
if (action.type === 'NEW_NOTE') {
363+
// highlight-start
357364
return state.concat(action.payload)
365+
// highlight-stop
358366
}
359367

360368
return state
@@ -572,7 +580,9 @@ Adding a new note creates the state it returns with Array's _concat_ function. L
572580
const noteReducer = (state = [], action) => {
573581
switch(action.type) {
574582
case 'NEW_NOTE':
583+
// highlight-start
575584
return [...state, action.payload]
585+
// highlight-stop
576586
case 'TOGGLE_IMPORTANCE':
577587
// ...
578588
default:
@@ -743,8 +753,10 @@ Your application can have a modest appearance, nothing else is needed but button
743753
Let's add the functionality for adding new notes and changing their importance:
744754

745755
```js
756+
// highlight-start
746757
const generateId = () =>
747758
Number((Math.random() * 1000000).toFixed(0))
759+
// highlight-stop
748760

749761
const App = () => {
750762
// highlight-start

0 commit comments

Comments
 (0)