File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Expand file tree Collapse file tree 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'];
553553### Avoid Side Effects (part 2)
554554Side effects could also occur from inside a function. In JavaScript, primitives are
555555passed 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.
558562
559563** Bad:**
560564``` javascript
561- function userReducer (state , action ) {
565+ function (state , action ) {
562566 state .userProfile = action .payload ;
563567 return state;
564568}
You can’t perform that action at this time.
0 commit comments