File tree
Expand file treeCollapse file tree1 file changed
+10
-7
lines changed Expand file treeCollapse file tree1 file changed
+10
-7
lines changed Original file line number | Diff line number | Diff line change |
---|
@@ -562,18 +562,21 @@ be very expensive in terms of performance.
|
562 | 562 |
|
563 | 563 | **Bad:**
|
564 | 564 | ```javascript
|
565 |
| -function (state, action) { |
566 |
| -state.userProfile = action.payload; |
567 |
| -return state; |
| 565 | +const addItemToCart = function (cart, item) { |
| 566 | +cart.push({ item: item, date: Date.now() }); |
| 567 | + |
| 568 | +return cart; |
568 | 569 | }
|
569 | 570 | ```
|
570 | 571 |
|
571 | 572 | **Good:**
|
572 | 573 | ```javascript
|
573 |
| -function userReducer(state, action) { |
574 |
| -var s = Object.assign({}, state); |
575 |
| -s.userProfile = action.payload; |
576 |
| -return s; |
| 574 | +const addItemToCart = function (cart, item) { |
| 575 | +const c = Object.assign({}, cart); |
| 576 | + |
| 577 | +c.push({ item: item, date: Date.now() }); |
| 578 | + |
| 579 | +return c; |
577 | 580 | }
|
578 | 581 | ```
|
579 | 582 |
|
|
You can’t perform that action at this time.
0 commit comments