How do I migrate a
LWC when I use Aura
Id for finding?
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 community
I have found the LWC docs to offload some of this to the MDN docs, so bringing this one layer higher (in the actual LWC docs would be nice) would have made it easier for us.
In scenarios where there are two components of the same type on your template, the equivalent to
aura:id is to use a
data-id tag and select it like this:
The equivalent of using
component.find() in LWC is to use a standard DOM query selector like this:
const element = this.template.querySelector('selector'); element.doSomething();
We do have a restrictions to that standard behavior: you cannot use the
id attribute as a selector as these are autogenerated by the framework.
You are free to use any tag name or CSS class to filter the element that you wish to retrieve.