-
-
Save arun12209/bd081235ccf57cf6ed0bf4b75a0ab50d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { LightningElement } from 'lwc'; | |
export default class ReactivityExample extends LightningElement { | |
bool = true; | |
number = 42; | |
obj = { name: 'John' }; | |
checkMutation() { | |
this.bool = false; // Mutation detected | |
this.number = 42; // No mutation detected: previous value is equal to the newly assigned value | |
this.number = 43; // Mutation detected | |
this.obj.name = 'Bob'; // No mutation detect: `obj` field value is not reassigned | |
this.obj = { name: 'John' }; // Mutation detected - redefining the object with the same value creates a new object | |
this.obj = { ...this.obj, title: 'CEO' } // Mutation detected | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment