Skip to content

Instantly share code, notes, and snippets.

@arun12209
Created January 15, 2023 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arun12209/bd081235ccf57cf6ed0bf4b75a0ab50d to your computer and use it in GitHub Desktop.
Save arun12209/bd081235ccf57cf6ed0bf4b75a0ab50d to your computer and use it in GitHub Desktop.
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