Aura:If vs Styling to show/hide content
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty{ margin-bottom:0;
}
up vote
4
down vote
favorite
Are there any benefits/negatives from either of the approaches below to conditionally show content in a Lightning component?
<aura:if isTrue="{! v.myBoolean }">
The Content
</aura:id>
versus
<div class="{! v.myBoolean ? 'slds-show' : 'slds-hide'}">
The Content
</div>
lightning-components slds aura-if
add a comment |
up vote
4
down vote
favorite
Are there any benefits/negatives from either of the approaches below to conditionally show content in a Lightning component?
<aura:if isTrue="{! v.myBoolean }">
The Content
</aura:id>
versus
<div class="{! v.myBoolean ? 'slds-show' : 'slds-hide'}">
The Content
</div>
lightning-components slds aura-if
aura:if causes DOM changes which is costly performance-wise. Use class approach whether applicable. Of course, there are situations where you might prefer aura:if - for example when you'd have to render many complex components in iteration, but that is left for your judgment. On another note, when using class - the body will be initialized immediately, whereas aura:if will initialize it's body every time isTrue attribute changes value to "true". Sometimes you don't want the component inside to be initialized before something else happens.
– pkozuchowski
12 hours ago
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
Are there any benefits/negatives from either of the approaches below to conditionally show content in a Lightning component?
<aura:if isTrue="{! v.myBoolean }">
The Content
</aura:id>
versus
<div class="{! v.myBoolean ? 'slds-show' : 'slds-hide'}">
The Content
</div>
lightning-components slds aura-if
Are there any benefits/negatives from either of the approaches below to conditionally show content in a Lightning component?
<aura:if isTrue="{! v.myBoolean }">
The Content
</aura:id>
versus
<div class="{! v.myBoolean ? 'slds-show' : 'slds-hide'}">
The Content
</div>
lightning-components slds aura-if
lightning-components slds aura-if
asked 12 hours ago
Girbot
3,56511839
3,56511839
aura:if causes DOM changes which is costly performance-wise. Use class approach whether applicable. Of course, there are situations where you might prefer aura:if - for example when you'd have to render many complex components in iteration, but that is left for your judgment. On another note, when using class - the body will be initialized immediately, whereas aura:if will initialize it's body every time isTrue attribute changes value to "true". Sometimes you don't want the component inside to be initialized before something else happens.
– pkozuchowski
12 hours ago
add a comment |
aura:if causes DOM changes which is costly performance-wise. Use class approach whether applicable. Of course, there are situations where you might prefer aura:if - for example when you'd have to render many complex components in iteration, but that is left for your judgment. On another note, when using class - the body will be initialized immediately, whereas aura:if will initialize it's body every time isTrue attribute changes value to "true". Sometimes you don't want the component inside to be initialized before something else happens.
– pkozuchowski
12 hours ago
aura:if causes DOM changes which is costly performance-wise. Use class approach whether applicable. Of course, there are situations where you might prefer aura:if - for example when you'd have to render many complex components in iteration, but that is left for your judgment. On another note, when using class - the body will be initialized immediately, whereas aura:if will initialize it's body every time isTrue attribute changes value to "true". Sometimes you don't want the component inside to be initialized before something else happens.
– pkozuchowski
12 hours ago
aura:if causes DOM changes which is costly performance-wise. Use class approach whether applicable. Of course, there are situations where you might prefer aura:if - for example when you'd have to render many complex components in iteration, but that is left for your judgment. On another note, when using class - the body will be initialized immediately, whereas aura:if will initialize it's body every time isTrue attribute changes value to "true". Sometimes you don't want the component inside to be initialized before something else happens.
– pkozuchowski
12 hours ago
add a comment |
2 Answers
2
active
oldest
votes
up vote
3
down vote
The benefit of aura:if is it does not even create the content inside its block if the conditions are false, thus it can help you make lightweight applications.
Hiding a div via CSS will still create the block and thus I feel, it will be bad for performance.
According to Salesforce docs
Using the aura:if tag is the preferred approach to conditionally
display markup but there are alternatives. Consider the performance
cost and code maintainability when you design components. The best
design choice depends on your use case.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_conditional_markup.htm?search_text=aura:if
add a comment |
up vote
0
down vote
First of all you don't need to use slds-show. If you remove 'slds-hide' the component displays anyway, but that's not the main question here.
Difference between those two is that <aura:if/> actually removes instance of contents from your page and slds-hide just hides it from view. Removing contents from page is usually better for optimization but keep in mind that if you re-instantiate them on a runtime they'll be back at the original state (just as you coded them in the first place).
New contributor
Bartosz Śliwiński is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
The benefit of aura:if is it does not even create the content inside its block if the conditions are false, thus it can help you make lightweight applications.
Hiding a div via CSS will still create the block and thus I feel, it will be bad for performance.
According to Salesforce docs
Using the aura:if tag is the preferred approach to conditionally
display markup but there are alternatives. Consider the performance
cost and code maintainability when you design components. The best
design choice depends on your use case.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_conditional_markup.htm?search_text=aura:if
add a comment |
up vote
3
down vote
The benefit of aura:if is it does not even create the content inside its block if the conditions are false, thus it can help you make lightweight applications.
Hiding a div via CSS will still create the block and thus I feel, it will be bad for performance.
According to Salesforce docs
Using the aura:if tag is the preferred approach to conditionally
display markup but there are alternatives. Consider the performance
cost and code maintainability when you design components. The best
design choice depends on your use case.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_conditional_markup.htm?search_text=aura:if
add a comment |
up vote
3
down vote
up vote
3
down vote
The benefit of aura:if is it does not even create the content inside its block if the conditions are false, thus it can help you make lightweight applications.
Hiding a div via CSS will still create the block and thus I feel, it will be bad for performance.
According to Salesforce docs
Using the aura:if tag is the preferred approach to conditionally
display markup but there are alternatives. Consider the performance
cost and code maintainability when you design components. The best
design choice depends on your use case.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_conditional_markup.htm?search_text=aura:if
The benefit of aura:if is it does not even create the content inside its block if the conditions are false, thus it can help you make lightweight applications.
Hiding a div via CSS will still create the block and thus I feel, it will be bad for performance.
According to Salesforce docs
Using the aura:if tag is the preferred approach to conditionally
display markup but there are alternatives. Consider the performance
cost and code maintainability when you design components. The best
design choice depends on your use case.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_conditional_markup.htm?search_text=aura:if
edited 10 hours ago
answered 12 hours ago
Pranay Jaiswal
10.9k31951
10.9k31951
add a comment |
add a comment |
up vote
0
down vote
First of all you don't need to use slds-show. If you remove 'slds-hide' the component displays anyway, but that's not the main question here.
Difference between those two is that <aura:if/> actually removes instance of contents from your page and slds-hide just hides it from view. Removing contents from page is usually better for optimization but keep in mind that if you re-instantiate them on a runtime they'll be back at the original state (just as you coded them in the first place).
New contributor
Bartosz Śliwiński is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
First of all you don't need to use slds-show. If you remove 'slds-hide' the component displays anyway, but that's not the main question here.
Difference between those two is that <aura:if/> actually removes instance of contents from your page and slds-hide just hides it from view. Removing contents from page is usually better for optimization but keep in mind that if you re-instantiate them on a runtime they'll be back at the original state (just as you coded them in the first place).
New contributor
Bartosz Śliwiński is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
up vote
0
down vote
First of all you don't need to use slds-show. If you remove 'slds-hide' the component displays anyway, but that's not the main question here.
Difference between those two is that <aura:if/> actually removes instance of contents from your page and slds-hide just hides it from view. Removing contents from page is usually better for optimization but keep in mind that if you re-instantiate them on a runtime they'll be back at the original state (just as you coded them in the first place).
New contributor
Bartosz Śliwiński is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
First of all you don't need to use slds-show. If you remove 'slds-hide' the component displays anyway, but that's not the main question here.
Difference between those two is that <aura:if/> actually removes instance of contents from your page and slds-hide just hides it from view. Removing contents from page is usually better for optimization but keep in mind that if you re-instantiate them on a runtime they'll be back at the original state (just as you coded them in the first place).
New contributor
Bartosz Śliwiński is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 12 hours ago
New contributor
Bartosz Śliwiński is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 12 hours ago
Bartosz Śliwiński
13
13
New contributor
Bartosz Śliwiński is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Bartosz Śliwiński is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Bartosz Śliwiński is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f240348%2fauraif-vs-styling-to-show-hide-content%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
aura:if causes DOM changes which is costly performance-wise. Use class approach whether applicable. Of course, there are situations where you might prefer aura:if - for example when you'd have to render many complex components in iteration, but that is left for your judgment. On another note, when using class - the body will be initialized immediately, whereas aura:if will initialize it's body every time isTrue attribute changes value to "true". Sometimes you don't want the component inside to be initialized before something else happens.
– pkozuchowski
12 hours ago