Invoke Apex method using @wire decorator in LWC
This is the first and simple variant when it comes to invoking an Apex method from LWC, which is by using @wire decorator.
This is the first and simple variant when it comes to invoking an Apex method from LWC.
The name itself conveys everything, we will be wiring the output of the apex method to a property.
If the apex method returns back a Map, then it will be received as an object by the property, if the apex method sends back a List it will be received as an Array in the Web Component.
Let’s look at how to draft the code in such a way the data is sent back by apex method and wired to the property.
Here is the JavaScript file of the Web Component.
In the template file we are iterating through the list. Note that we will be using {records.data}
and not record in <template for:each for:item>
tag.
Hope this is helpful!