Skip to content

Commit a4718d4

Browse files
authored
Change example
1 parent daf2d6c commit a4718d4

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

README.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -562,18 +562,21 @@ be very expensive in terms of performance.
562562

563563
**Bad:**
564564
```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;
568569
}
569570
```
570571

571572
**Good:**
572573
```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;
577580
}
578581
```
579582

0 commit comments

Comments
 (0)