Last active
February 25, 2024 22:19
-
-
Save arufian/790f5004d33081f6bd207271dab43668 to your computer and use it in GitHub Desktop.
How to use dynamic fields at @wire getRecord - LWC (Lightning Web Component)
This file contains hidden or 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, track, wire, api } from 'lwc'; | |
export default class DynamicFields extends LightningElement { | |
@api recordId; | |
@track fields; | |
@api objectApiName; | |
@wire(getRecord, { recordId: '$recordId', fields: '$fields' }) | |
record; | |
connectedCallback() { | |
this.fields = this.objectApiName === 'Account'? ['Account.BillingCity', 'Account.Name']: ['Contact.MailingCity', 'Contact.Name']; | |
} | |
renderedCallback() { | |
console.log(this.record, 'record'); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment