0

Would it be best practice to use only one @wire getRecord in the top-level component and then pass the subsequent data around? or is it okay to use @wire getRecord in all components and instead just pass the recordId around?

PARENT COMPONENT JS:

   @api recordId;
    _error;

    @wire(getNewestMergeId, { })
    wireNewestMergeId({ error, data }){
        if (data) {
            this.recordId = data;
            this._error = undefined;
        } else if (error) {
            this._error = error;
            this.recordId = undefined;
        } else {
            this._error = undefined;
            this.recordId = undefined;
        }
    }

    @wire(getRecord, { recordId: '$recordId', fields: [ID_FIELD, NAME_FIELD, STATUS_FIELD] })
    _merge;

PARENT COMPONENT HTML

<template>
    <div class="slds-grid slds-gutters_xx-small">
        {_mergeStatus}
        <div class="slds-col slds-size_2-of-3">
            <c-bulk-merge-primary-container merge={_merge}></c-bulk-merge-primary-container>
        </div>
        <div class="slds-col slds-size_1-of-3">
            <c-bulk-merge-secondary-container merge={_merge}></c-bulk-merge-secondary-container>
        </div>
    </div>
</template>

1 Answer 1

0

As a general rule use the service; as with all wires the infrastructure maintains a client-side cache of the data so you will not incur any additional network overheads (the server is invoked once and the result shared).

Also note that the infrastructure will automatically rerender all components that share that same cache if and when the value changes.

This is covered in the documentation.

This approach allows low coupling of the components, making them more reusable.

Obviously, if you have a hierarchy of components, the parent template would cause the children to be rerendered if the data changes, and those child components are never going to be used or exposed outside this context, you certainly can pass the SObject data around. It rather depends on the specific use case and complexity of your components.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .