Skip to content

Instantly share code, notes, and snippets.

@JitendraZaa
Created May 4, 2020 23:11
Show Gist options
  • Save JitendraZaa/7f1253ef9ab2b0234fb2cba14118e194 to your computer and use it in GitHub Desktop.
Save JitendraZaa/7f1253ef9ab2b0234fb2cba14118e194 to your computer and use it in GitHub Desktop.
.roundImg{
border-radius: 50%;
}
<template>
<div>
<img src={imgSrc} class={cssClass} />
</div>
</template>
import { LightningElement, api, track, wire } from 'lwc';
import getMD5Hash from '@salesforce/apex/GravatarController.getMD5Hash';
export default class Gravatar extends LightningElement {
@api size;
@api email;
@track emailHash = '66f795f030fcc5290902fd41eb7386fe';
@api isRoundCorner;
//Advantage of getter - if any of property changes like size, it would cause rebinding on UI
get imgSrc(){
if(!this.size){
this.size = 150;
}
return "https://www.gravatar.com/avatar/"+this.emailHash+"?s="+this.size;
}
//Advantage of getter - if any of property changes like isroundedcorner, it would cause rebinding on UI
get cssClass(){
if(this.isRoundCorner){
return 'roundImg';
}
}
@wire( getMD5Hash , {email : '$email'})
wireMethodCallback({error,data}){
if(data){
this.emailHash = data;
}
}
connectedCallback() {
// initialize component - equivalent to init method of Aura
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment