LWC Interview
LWC Interview
@wire(getBoats,{boatTypeId : ‘$boatTypeId’})
getBoats(result){
this.mainResult = result;
if(result.data){
this.someVar = result.data;
this.error = undefined;
}
else if(result.error){
this.error = result.error;
this.someVar = undefined ;
}
}
Now we can refresh data as
refreshApex(this.mainResult)
6. Can we call a wire function inside a
javascript function like below :
searchBoats(event){
@wire(getBoats,{boatTypeId: ‘$boatTypeId’}
getBoats(data,error){
}
}
Assume searchBoats is being called on click of
button? Will I be able to deploy the code ?
@wire(getBoats)
getBoats({myData,myError}){
if(mydata)
console.log(‘i am in data’);
else if(myError)
console.log(‘I am in error’); }
Will the code deploy successfully or I will receive
an error ?
9. What is the difference in below two codes ,
will they both compile ? Give same results ?
Code 1 :
@wire(getBoats)
getBoats({data,error}){
if(data)
console.log(‘print here’);
Else if(error)
console.log(‘print in else’);
}
@wire(getBoats,{})
getBoats({error,data}){
if(data)
console.log(‘print here’);
Else if(error)
console.log(‘print in else’);
}
Ans: Both will compile they are same.
10. What is the difference between
event.StopPropogation() and
Event.preventDefault()?
Ans: stopPropagation prevents further
propagation of the current event in the capturing
and bubbling phases. preventDefault prevents the
default action the browser makes on that event.