Skip to content

Instantly share code, notes, and snippets.

@madmax983
Last active May 21, 2021 18:15
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 madmax983/a86100420e77dc837635bbbebe824828 to your computer and use it in GitHub Desktop.
Save madmax983/a86100420e77dc837635bbbebe824828 to your computer and use it in GitHub Desktop.
LWC Debugging Tips and Tricks
<template>
{lwcPrettyProperty}
</template>
import { LightningElement } from 'lwc';
export default class PrettyPrintProperty extends LightningElement {
property;
get lwcPrettyProperty() {
return JSON.stringify(this.property, null, 4);
}
}
<template>
{prettyContacts}
<button onclick={handleRefresh}>Refresh</button>
</template>
import { LightningElement } from 'lwc';
import { refreshApex } from '@salesforce/apex';
import getContacts
from "@salesforce/apex/ContactController.getContacts";
export default class TestCacheableApexOnDemand extends LightningElement {
@wire(getcontacts)
contacts;
handleRefresh() {
refreshApex(this.contacts);
}
get prettyContacts() {
return JSON.stringify(this.contacts, null, 4);
}
}
@madmax983
Copy link
Author

The pretty print of wires properties also works great for generating your mock json files for testing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment