Getting data can be done in at least 2 ways in LWC:
- Call the apex method imperatively (e.g. in connectedCallback)
- Wire the apex method
In my use case, data to be fetched is static and is not subject to change when parameters are changed.
@wire(getFieldSetFields, {
objectName: CASE_SOBJECT.objectApiName,
fieldSetName: CASE_RECORD_OVERVIEW_FIELDSET_NAME
})
wiredCaseFieldSetFields;
vs
async connectedCallback(){
const results = await getFieldSetFields({
objectName: CASE_SOBJECT.objectApiName,
fieldSetName: CASE_RECORD_OVERVIEW_FIELDSET_NAME
})
}
Now, my question is: for static data (data not subject to change due to changing variables), what seems the 'best' approach to get the data?
A few things I see:
Pro's for wiring:
- Code Readability
- Static data can be cached
Pro's for connectedCallback:
- No checking if wired property contains data
connectedCallback
async and suggests a couple of alternatives. However, I see that some of the Salesforce examples (such as that for the lightning-datatable's basic.js do actually do this.