LWC Best Practices

1. Use the Lightning Data Service or cache data whenever possible

2. Before making a call to the server, make sure there's no other option to obtain the data

3. Consider passing data between components using attributes, events, or methods rather than retrieving the same data in different components 4. If multiple components on a given page retrieve the same data, consider creating a service component that has no UI elements and

can query data once so that it can pass data on to other components.

5. Only SELECT the fields you need.

6. Set a LIMIT on the query, don't return huge numbers of rows at once

7. Implement pagination when queries may have large result sets.

8. Don't preload data that the user may never need

9. Put the least accessed components in a secondary tab that the user may not click.

10. Don't make a call to the server to filter or sort data you already have at the client side.

JavaScript Arrays have built-in functions to do things like sort, filter, and find values.

11. As opposed to using Apex, leverage the Lightning Data Service and UI API to not only retrieve records.

but also retrieve list views, metadata, and picklist values.

12. When using the getRecord wire adapter (part of the UI API), request only the fields that the component requires. Be explicit.

For example, if the component requires one field, request only that field.

13. Don't request a record by layout unless you absolutely need all that data.


Comments

Popular posts from this blog

What are Duplicate Rules and Matching Rules? How to Invoke Duplicate and Matching Rules in Salesforce without performing DML operations?

Apex Best Practices