mirror of
https://github.com/github/awesome-copilot.git
synced 2026-02-23 03:45:13 +00:00
Update instructions/lwc.instructions.md
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -170,33 +170,33 @@ export default class MyComponent extends LightningElement {
|
|||||||
// @track is NOT needed for simple property reassignment
|
// @track is NOT needed for simple property reassignment
|
||||||
// This will trigger reactivity automatically:
|
// This will trigger reactivity automatically:
|
||||||
handleUpdate() {
|
handleUpdate() {
|
||||||
this.simpleValue = 'updated'; // Reactive without @track
|
this.simpleValue = 'updated'; // Reactive without @track
|
||||||
this.count++; // Reactive without @track
|
this.count++; // Reactive without @track
|
||||||
}
|
}
|
||||||
|
|
||||||
// @track IS needed when mutating nested properties without reassignment
|
// @track IS needed when mutating nested properties without reassignment
|
||||||
@track complexData = {
|
@track complexData = {
|
||||||
user: {
|
user: {
|
||||||
name: 'John',
|
name: 'John',
|
||||||
preferences: {
|
preferences: {
|
||||||
theme: 'dark'
|
theme: 'dark'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
handleDeepUpdate() {
|
handleDeepUpdate() {
|
||||||
// Requires @track because we're mutating a nested property
|
// Requires @track because we're mutating a nested property
|
||||||
this.complexData.user.preferences.theme = 'light';
|
this.complexData.user.preferences.theme = 'light';
|
||||||
}
|
}
|
||||||
|
|
||||||
// BETTER: Avoid @track by using immutable patterns
|
// BETTER: Avoid @track by using immutable patterns
|
||||||
regularData = {
|
regularData = {
|
||||||
user: {
|
user: {
|
||||||
name: 'John',
|
name: 'John',
|
||||||
preferences: {
|
preferences: {
|
||||||
theme: 'dark'
|
theme: 'dark'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
handleImmutableUpdate() {
|
handleImmutableUpdate() {
|
||||||
|
|||||||
Reference in New Issue
Block a user