@state decorator declares an internal reactive property. Like @property, changing a state property
schedules an element update. Unlike @property, state properties are not backed by HTML attributes and
are not intended to be set by users of the element.
Import
Signature
Options
A function that determines whether a change to the property should trigger
an update. Return
true to request an update. Defaults to strict inequality
(!==).Usage
@state vs @property
@state | @property | |
|---|---|---|
| Triggers re-render | Yes | Yes |
| Backed by attribute | No | Yes (by default) |
| Visible from HTML | No | Yes |
| Can be renamed by minifiers | Yes | No |
| Intended audience | Internal element logic | Public API |
@state for values that are internal implementation details of your element — things
like whether a dropdown is open, or intermediate values computed during user interaction.
Use @property for values that element users can configure
from HTML or JavaScript, such as a name or disabled flag.
Without decorators
Without decorators, declare a state property usingstatic properties with state: true: