Skip to content

Commit 65cd668

Browse files
authored
Merge pull request #3828 from anttiharju/source
Remove confusing negation in part2d
2 parents 3ef54a3 + 0ea95fb commit 65cd668

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/content/2/en/part2d.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ const toggleImportanceOf = id => {
204204
const changedNote = { ...note, important: !note.important }
205205

206206
axios.put(url, changedNote).then(response => {
207-
setNotes(notes.map(n => n.id !== id ? n : response.data))
207+
setNotes(notes.map(n => n.id === id ? response.data : n))
208208
})
209209
}
210210
```
@@ -243,17 +243,17 @@ The callback function sets the component's <em>notes</em> state to a new array t
243243
244244
```js
245245
axios.put(url, changedNote).then(response => {
246-
setNotes(notes.map(note => note.id !== id ? note : response.data))
246+
setNotes(notes.map(note => note.id === id ? response.data : note))
247247
})
248248
```
249249
250250
This is accomplished with the <em>map</em> method:
251251
252252
```js
253-
notes.map(note => note.id !== id ? note : response.data)
253+
notes.map(note => note.id === id ? response.data : note)
254254
```
255255
256-
The map method creates a new array by mapping every item from the old array into an item in the new array. In our example, the new array is created conditionally so that if <em>note.id !== id</em> is true; we simply copy the item from the old array into the new array. If the condition is false, then the note object returned by the server is added to the array instead.
256+
The map method creates a new array by mapping every item from the old array into an item in the new array. In our example, the new array is created conditionally so that if <em>note.id === id</em> is true; the note object returned by the server is added to the array. If the condition is false, then we simply copy the item from the old array into the new array instead.
257257
258258
This <em>map</em> trick may seem a bit strange at first, but it's worth spending some time wrapping your head around it. We will be using this method many times throughout the course.
259259
@@ -320,7 +320,7 @@ const App = () => {
320320
noteService
321321
.update(id, changedNote)
322322
.then(response => {
323-
setNotes(notes.map(note => note.id !== id ? note : response.data))
323+
setNotes(notes.map(note => note.id === id ? response.data : note))
324324
})
325325
// highlight-end
326326
}
@@ -448,7 +448,7 @@ const App = () => {
448448
.update(id, changedNote)
449449
// highlight-start
450450
.then(returnedNote => {
451-
setNotes(notes.map(note => note.id !== id ? note : returnedNote))
451+
setNotes(notes.map(note => note.id === id ? returnedNote : note))
452452
// highlight-end
453453
})
454454
}
@@ -665,7 +665,7 @@ const toggleImportanceOf = id => {
665665

666666
noteService
667667
.update(id, changedNote).then(returnedNote => {
668-
setNotes(notes.map(note => note.id !== id ? note : returnedNote))
668+
setNotes(notes.map(note => note.id === id ? returnedNote : note))
669669
})
670670
// highlight-start
671671
.catch(error => {

0 commit comments

Comments
 (0)