File tree 1 file changed +7
-3
lines changed
1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -553,12 +553,16 @@ console.log(newName); // ['Ryan', 'McDermott'];
553
553
### Avoid Side Effects (part 2)
554
554
Side effects could also occur from inside a function. In JavaScript, primitives are
555
555
passed by value and objects are passed by reference. In the later case, we should be
556
- careful not to change any of these argument's properties. A possible solution would
557
- be to always clone the variable, edit it and return the clone.
556
+ careful not to change any of these argument's properties.
557
+
558
+ A possible solution would be to always clone the variable, edit it and return the
559
+ clone. There would be cases where you actually want to modify the input object
560
+ and this should not be taken as a silver bullet. Furthermore, cloning big objects can
561
+ be very expensive in terms of performance.
558
562
559
563
** Bad:**
560
564
``` javascript
561
- function userReducer (state , action ) {
565
+ function (state , action ) {
562
566
state .userProfile = action .payload ;
563
567
return state;
564
568
}
You can’t perform that action at this time.
0 commit comments