[SalesForce] Lightning Component Best Practices

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?

Best Answer

These can be found at Lightning Components Performance Best Practices

  1. Data retrieval
  2. Data caching
  3. Component instantiation
  4. Conditional rendering
  5. Data binding
  6. Lists (aura:iteration)
  7. Events
  8. Third-party JavaScript libraries
  9. Base Lightning Components
  10. Image optimization
  11. Rendering and reflow
  12. Development settings vs production settings
  13. Performance profiling tools

The above links all point towards the same linked Blog above, but redirect to their section.

Events Best Practices

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.

Related Topic