Sub topic 4
Receiving flow values in your component
This chapter covers how a screen flow passes values into a Lightning web component. It assumes you can write a basic LWC with @api properties, that you know what a screen flow variable is, and that you have already exposed a component with the lightning__FlowScreen target.
How the flow delivers values
A component receives flow values through public properties, the same @api mechanism a parent component uses. The flow runtime acts as the parent. For each <property> in the targetConfig of your meta.xml, the runtime sets the matching @api property on your component instance. Whatever the flow builder entered in the property field is what arrives. That can be a literal, a variable, a resource, or a formula.
The name in the meta.xml must match the JavaScript property name exactly, including case. If it doesn't, Flow Builder shows an input that the component never receives.
A minimal input
The Quantity Picker from the earlier chapters already has two inputs. Here is the declaration again, with the roles spelled out:
<targetConfig targets="lightning__FlowScreen">
<property name="label" type="String" role="inputOnly" label="Field label" default="Quantity"/>
<property name="quantity" type="Integer" label="Quantity"/>
</targetConfig>The JavaScript side only needs matching @api properties:
import { LightningElement, api } from 'lwc';
export default class QuantityPicker extends LightningElement {
@api label = 'Quantity';
@api quantity;
}Two defaults are involved here, and they are separate. The default attribute in the meta.xml pre-fills the field in Flow Builder. The = 'Quantity' in JavaScript applies when no value is passed at all. Keep them the same so the component behaves identically in both cases.
Supported property types
The type attribute decides what Flow Builder offers in the value picker and what JavaScript receives.
| meta.xml type | Flow data type | JavaScript value |
|---|---|---|
| `String` | Text | string |
| `Integer` | Number (no decimal places) | number |
| `Boolean` | Boolean | boolean |
| `Date` | Date | string such as `2026-11-30` |
| `DateTime` | Date/Time | ISO 8601 string |
| `String[]` | Text collection | array of strings |
| `{T}` or `{T[]}` | sObject record or collection | object or array of objects |
Dates and date-times arrive as strings, not Date objects. Convert them yourself if you need to compare or format them.
Inputs can be missing
A flow variable that has never been assigned arrives as null or undefined. An unset collection may arrive as undefined rather than an empty array. Treat every input as possibly empty:
get hasQuantity() {
return Number.isInteger(this.quantity);
}A common bug is calling .map() or .length on a collection input that turns out to be undefined. Guard with Array.isArray(value) before you use it.
Use a setter when you must react to a value
A plain @api field is fine when you only render the value. When you need to compute something from an input, use a getter and setter pair. Put @api on the getter only, because decorating both is a compile error.
This component takes a collection of text choices and builds a list with stable keys:
<targetConfig targets="lightning__FlowScreen">
<property name="choices" type="String[]" label="Choices" role="inputOnly"/>
</targetConfig>import { LightningElement, api } from 'lwc';
export default class ChoiceList extends LightningElement {
_choices = [];
rows = [];
@api
get choices() {
return this._choices;
}
set choices(value) {
this._choices = Array.isArray(value) ? value : [];
this.rows = this._choices.map((text, index) => ({
key: `choice-${index}`,
text
}));
}
}<template>
<ul>
<template for:each={rows} for:item="row">
<li key={row.key}>{row.text}</li>
</template>
</ul>
</template>The setter runs each time the flow assigns a new value. It runs before connectedCallback, so do not touch child elements or the DOM inside it.
Do not rely on the order in which the flow sets properties. If a calculation needs two inputs, compute it in a getter that reads both fields, or call a shared method from both setters and have that method check that each input is present.
Treat inputs as read-only
Values from the flow belong to the flow. In particular:
- Objects and arrays arrive wrapped in read-only proxies. Changing a field or calling
push()on them throws an error or fails silently, depending on the case. - Assigning a new value to an input property from inside the component changes only your local copy. The flow does not see it. Only a
FlowAttributeChangeEventreports a change back, and that is the next chapter's subject.
To edit a record or list, copy it first:
const draft = { ...this.record };
draft.Name = 'Updated name';
const draftList = this.items.map((item) => ({ ...item }));A shallow spread is enough for flat sObject records. Records that contain related records need a deeper copy, for example structuredClone.
What the component sees when the user navigates back
The runtime destroys the component when the user leaves the screen and builds a new instance when they return. Local fields therefore reset to their initial values. The flow passes in only the values it holds, so a value survives navigation only if:
- the property is an output (or input and output), and
- the component reported the value with
FlowAttributeChangeEvent.
If a user types a quantity, clicks Next, and then clicks Back, the component receives quantity as an input again, because the flow stored it. Anything you kept only in a private field is gone. Design components so that the inputs are enough to rebuild the screen state.
Reacting to changed inputs
A flow can change an input while the screen is showing. For example, a Reactive screen component or another component on the same screen may update a variable. When that happens the runtime sets the @api property again on the same instance, and your setter runs again. Write setters so that repeated calls are safe, and avoid actions with side effects such as dispatching events from inside a setter. A setter that fires FlowAttributeChangeEvent for the value it just received can cause a loop of updates between the flow and the component.
Common errors
| Symptom | Likely cause |
|---|---|
| Input shows in Flow Builder but is always `undefined` | `name` in meta.xml differs from the JavaScript property name, including case |
| `Cannot assign to read only property` error | Mutating an object or array that came from the flow |
| `.map is not a function` | Collection input was `undefined` or `null` and the code did not guard for it |
| Date comparison always false | The flow passed a string and the code compared it with a `Date` object |
| Compile error on the setter | `@api` placed on both getter and setter |
| Value is lost after Back | Value was kept in a private field and never sent as an output |
Exercises
Exercise
A flow passes a Text collection into your component through the property choices. The component calls this.choices.sort() and gets an error. Why does it fail, and how do you fix it?
Show answer
The array from the flow is a read-only proxy, and sort() changes the array in place. Copy it first, for example [...this.choices].sort(), and sort the copy.
Exercise
Your component reads this.startDate from a Date input and runs this.startDate.getFullYear(). What goes wrong, and what should you do?
Show answer
Date inputs arrive as strings such as "2026-11-30", so getFullYear does not exist on them. Build a Date from the string, for example new Date(this.startDate), after checking that the value is not empty.
Exercise
A user enters 5 in your component, clicks Next, then clicks Back. The field is empty. The quantity property is declared in the meta.xml. Name two things to check.
Show answer
Check that the component dispatches FlowAttributeChangeEvent('quantity', value) when the value changes, and that the property is not marked role="inputOnly". Without an output, the flow never stores the value and has nothing to pass back in.