Q: How do you perform navigation to a record page in LWC? A: You use the NavigationMixin
from lightning/navigation
to navigate to a record page.
Q: What is a reactive getter in LWC? A: A reactive getter is a getter that automatically updates when its dependent properties change.
Q: How do you import external JavaScript libraries in LWC? A: You import external JavaScript libraries by uploading them as static resources and referencing them using loadScript
from lightning/platformResourceLoader
.
Q: How do you detect changes to properties in LWC? A: You detect changes to properties by using setters, getters, or by monitoring the properties within lifecycle hooks like renderedCallback
.
Q: How do you handle form validation in LWC? A: You handle form validation by adding validation logic in your JavaScript code and using HTML5 form validation attributes.
Q: What is the lightning-button
component? A: The lightning-button
component is a standard button component in LWC that supports SLDS styling.
Q: How do you set default values for input fields in LWC? A: You set default values for input fields by initializing the property in your JavaScript class and binding it to the input field.
Q: How do you optimize performance in LWC? A: You optimize performance by minimizing DOM updates, using wire services for data retrieval, and leveraging native JavaScript optimizations.
Q: How do you dynamically add and remove CSS classes in LWC? A: You dynamically add and remove CSS classes using JavaScript, e.g., classList.add
and classList.remove
.
Q: What is the renderedCallback
lifecycle hook used for? A: It is used to perform actions after the component has rendered, such as manipulating the DOM.
Q: How do you enable inline editing in lightning-datatable
? A: You enable inline editing by setting the editable
attribute on the lightning-datatable
columns.
Q: How do you create a tabbed interface in LWC? A: You create a tabbed interface using lightning-tabset
and lightning-tab
components.
Q: How do you handle complex state in LWC? A: You handle complex state by using JavaScript classes, objects, and reactive properties.
Q: How do you test LWC components? A: You test LWC components using Jest, the JavaScript testing framework recommended by Salesforce.
Q: What is the lightning-record-view-form
component? A: The lightning-record-view-form
component is a built-in LWC component that displays a record’s details in a read-only form.
Q: How do you handle asynchronous operations in LWC? A: You handle asynchronous operations using Promises, async/await
, or wire adapters.
Q: How do you pass data to a child component in LWC? A: You pass data to a child component using public properties decorated with @api
.
Q: How do you use Lightning App Builder with LWC? A: You use Lightning App Builder to drag and drop LWC components onto Lightning pages.
Q: How do you implement pagination in LWC? A: You implement pagination by managing data chunks and navigation controls in your JavaScript class.
Q: How do you handle file uploads in LWC? A: You handle file uploads using the lightning-file-upload
component.
Q: How do you format currency in LWC? A: You format currency using the Intl.NumberFormat
object in JavaScript.
Q: How do you add a tooltip in LWC? A: You add a tooltip by using the title
attribute on HTML elements or the lightning-helptext
component.
Q: How do you handle deep object mutation in LWC? A: You handle deep object mutation by creating a new object with updated values to trigger reactivity.
Q: How do you use CSS variables in LWC? A: You use CSS variables by defining them in the component’s CSS file and referencing them in your styles.
Q: How do you restrict LWC components to specific record types? A: You restrict LWC components to specific record types by using component visibility rules in Lightning App Builder or programmatically in JavaScript.
Q: How do you create a custom Lightning App in LWC? A: You create a custom Lightning App by defining an app
component and including it in the c
namespace.
Q: How do you manage component state in LWC? A: You manage component state using reactive properties and JavaScript variables.
Q: What is the lwc:if
directive used for? A: The lwc:if
directive is used for conditional rendering of template content based on a Boolean expression.
Q: How do you integrate third-party APIs in LWC? A: You integrate third-party APIs by making HTTP calls from Apex and exposing the data to LWC components.
Q: How do you use the lightning-accordion
component in LWC? A: You use the lightning-accordion
component to create expandable and collapsible sections by including lightning-accordion-section
components within it.