Inspired from this question General trigger bulkification - best practices
I wanted to ask what are the best practices when it comes to lightning components development?
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityInspired from this question General trigger bulkification - best practices
I wanted to ask what are the best practices when it comes to lightning components development?
These can be found at Lightning Components Performance Best Practices
The above links all point towards the same linked Blog above, but redirect to their section.
Always try to use a component event instead of an application event, if possible.
Understanding JavaScript Controllers Versus Helpers In Lightning Components
When To Use Controllers v/s Helpers: Use Controllers to listen to user events and other events like component, application events. But delegate business logic to helper.
Just a some quick mentions,
Don't try to re-invent the wheel, when possible, leverage the provided Base components found in the Component Reference guide.
Mentioned in the blog, but worth repeating, Avoid Apex when possible.
Eventhough The above blog is oriented towards Performance Best Practices, I believe these go in Hand with Development Best Practices.
Leverage Salesforce's Lightning Design System when styling components.
Last but not least, learning how to debug your code is essential, I must admit, troubleshooting is not the easiest thing to do when developing in lightning, but this post How do I debug my lightning component? should provide useful.
I believe the above references are a good start for Best Practices when developing Lightning Components.
Rather a big subject to cover here... I offer these more as a list of things I have learned that might save others a bit of time than as a comprehensive list of best practices:
aura:html
components too so access via those componentsaura:id
values never on DOM id
valueslightning:*
components wherever possible because those have the SLDS styling wired in and are being invested in by Salesforce; but don't be surprised to hit bugs as the components are still quite newsfdx lightning:lint
tool{! ... }
and {# ... }
expressionsv.
prefix needed to access attributesv.body
I want to add my input on top of other comments.
Use Lightning Inter-Component Communication Patterns to pass data around lightning components.
If you create a component dynamically in JavaScript and that component isn't added to a facet (v.body or another attribute of type Aura.Component[]), you have to destroy it manually using Component.destroy() to avoid memory leaks.