Below are few questions which are asked me during my latest interviews :
22. I want to pass data from HTML file of Parent to Child in LWC?
Ans: WE can use slots to pass data from HTML file of Parent to Child.
23. What are the slots in LWC, explain with code ?
Ans: Slots allows component to interact, display and receive dynamic content from parent components.
Parent.html
<template>
<c-child-slot>
<p> i am unnamed slot</p>
<p slot="first"> i am unnamed slot new !</p>
</c-child-slot>
</template>
ChildSlot.html
<template>
<slot></slot>
<slot name="first" onslotchange={handlechange}></slot>
</template>
Child.js
import { LightningElement } from 'lwc';
export default class ChildSlot extends LightningElement {
handlechange(){
console.log('in handlechange');
}
}
OUTPUT:
24. What are the benefits slots in LWC?
Ans:
- Slots enable LWC components to interact dynamic content provided by Parent LWC.
- This helps in building of complex UI with multiple components.
- Slots provides reusability, as its allows Child LWC to work with different Parent LWC.
- Slots simplifying the overall application architecture.
25. What are the Promises in LWC?
Ans: In LWC, when we have to call methods Asynchronously, we can use Promises. Promises handles asynchronous operations and provide bettor error handling than events and callback.
Syntax:
var objPromise = new Promise(Function(resolve, reject)){
// your async code.
});
Promise takes one argument which is a callback function. Callback function have 2 parameters, resolve and reject. If everything works well then call resolve else reject.
Promises have 3 steps: Pending, Fulfilled, Rejected.
26. When to use @wire call?
Ans:
- We can use wire when we have to cached the Result.
- @wire adaptor are great to read the apex data.
- DML are not supported in @wire.
- When we have to do DML operations on database.
- Data cannot be cached.
Subscribe blog for More updates !!!
Latest Salesforce Interview Questions and Answers: