Jul 3, 2019

Basic: Lightning Web Components Tips & Tricks



Settings, tips and tricks for the everyday Lightning Web Component (LWC) development folks. This article is for developers and programmers at heart, context isn't necessary, so lets get right to it ..

  1. I like to import everything at the top of the js file with this line
    import { LightningElement, track, api, wire } from'lwc' 
  2. The recordId property decorated with @api automatically receives the current record id OR needs to be passed by the parent component when it calls the child component in html with the attribute record-id={obj.value}, where obj.value is either a hardcoded-id or retrieve via JS controller or passed by it's parent.
  3. Import a getRecord adapter that allows to use the Lightning Data Service (LDS) to retrieve records without having to write Apex.
    import { getRecord } from 'lightning/uiRecordApi';
  4. Once imported use the @wire decorator to retrieve data
    @wire(getRecord, {recordId:'$userId',fields: [ 'User.Name''User.ContactId''User.Email' ] } )user;
  5. More to come.

Whatsapp Button works on Mobile Device only

Start typing and press Enter to search