A service component is a component that provides an API for a set of functionalities. Ideally, the service should be specialized, generic and reusable. Also, it does not have a markup, i.e. it is not visible by default.
Creating a custom service simplifies component’s code and help reduce code duplication. This in turns makes the code more robust and facilitates maintenance.
To develop a custom service component for my Account object, I have created an
accountService
component and exposed the below services:searchAccount
: it accepts a search key and returns the list of accounts matching the keygetAccounts
: this returns a list of 5 accounts
accountComponent
which is consuming the services like below:Please see the below repo for the code:
https://github.com/iamsonal/lwc-service
References:
https://developer.salesforce.com/blogs/2018/08/implement-and-use-lightning-service-components.html