Skip to content

Instantly share code, notes, and snippets.

@JitendraZaa
Created May 5, 2020 01:21
Show Gist options
  • Save JitendraZaa/46a8860e99e2e96699e26a7fd89c4f98 to your computer and use it in GitHub Desktop.
Save JitendraZaa/46a8860e99e2e96699e26a7fd89c4f98 to your computer and use it in GitHub Desktop.
Jitendra Zaa Blog on how to define reusable LWC component to share Javascript code
<template>
... Some UI related code here
</template>
import { LightningElement , track } from 'lwc';
//Importing reusable LWC Component as Javascript utility
import {getUrlParameter } from 'c/JSUtility';
export default class DemoWrapperLWC extends LightningElement {
//Some track variables define
//......
//.. Some code
//Similar to init method in Aura
connectedCallback() {
//Note - We are NOT using "this" keyword to access method getUrlParameter
let param1 = getUrlParameter('param1');
console.log('Found Parameter value for param1'+param1);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>48.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__AppPage</target>
<target>lightning__RecordPage</target>
<target>lightning__HomePage</target>
<target>lightningCommunity__Page</target>
<target>lightningCommunity__Default</target>
</targets>
</LightningComponentBundle>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment