Handling expression-bound data in custom components
Key Takeaway
A custom component can render before its expression-bound data arrives, so check that each value is defined and of the correct type before you use it.
Expressions pull live store data into an LWR component in Experience Builder, so a component can show dynamic data instead of static text. Expression-bound data can arrive in pieces, which means a custom Lightning web component (LWC) may render before a value exists and then render again as the data fills in. Your code must cope with those early renders, or it can throw an error.
What expressions do
You can add custom Lightning web components to a B2B or D2C store built on an LWR template, alongside the standard Commerce components. To bring dynamic data into a custom component, use expressions, which make the store more customized and dynamic than static text can.
You can enter expressions into any LWR component on a page that has data providers. Some components let you pick an expression from a provided list. You can also combine expressions or add values.
The data you can reach depends on the page.
| Data expressions | Where they work |
|---|---|
| Cart | Components on the cart page |
| Order | Components on the order summary details page |
| Product | Components on the product page |
| Search | Components on the Search page |
| User field | Any LWR store page |