1

We are using multiple lightning:recordForm in different aura:if for the different condition in a single custom Lightning Component for showing different field. Is it the best practice to use multiple lightning:recordForm at a time?

<aura:if isTrue="{!v.check=='a'}">
    <lightning:recordForm 
        recordId="001XXXXXXXXXXXXXXX" 
        objectApiName="My_Contact__c"
        layoutType="Full" 
        mode="view" />
</aura:if>
<aura:if isTrue="{!v.check=='b'}">
    <lightning:recordForm 
        recordId="001XXXXXXXXXXXXXXX" 
        objectApiName="My_Contact__c"
        layoutType="Full" 
        mode="view" />
</aura:if>
<aura:if isTrue="{!v.check=='c'}">
    <lightning:recordForm 
        recordId="001XXXXXXXXXXXXXXX" 
        objectApiName="My_Contact__c"
        layoutType="Full" 
        mode="view" />
</aura:if>
  • 3
    Why not use if clause on fields? instead of on record form? seems like an overkill – Pranay Jaiswal Nov 8 '18 at 12:48
  • Thanks, @PranayJaiswal Yes, you are right. I will try in that way too. But my curiosity was to know the performance effect and best practice to use it. – sanket kumar Nov 8 '18 at 16:36
3

aura:if doesn't even create the components contained within unless isTrue is true. As such, you're really only creating one lightning:recordForm at a time as far as performance is concerned. You can expect nominal performance from this design, assuming there's not too many aura:if elements (they're pretty fast, but too many can be a performance concern), but you'd need a few hundred to feel any real performance penalty.

  • Thanks a lot for this valuable information, @sfdcfox. This information is not available anywhere as I tried to find it a lot. – sanket kumar Nov 8 '18 at 16:38
  • 1
    @sanketkumar it's in the documentation: "aura:if instantiates the components in either its body or the else attribute, but not both. ... If the state of isTrue changes, aura:if has to first instantiate the components for the other state and then render them. We recommend using aura:if instead of aura:renderIf to improve performance." – sfdcfox Nov 8 '18 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.