Component Instance
The API for a mounted component instance.
How instances are created
Section titled “How instances are created”Component instances are created from the component constructor via the mount() or mountAll() method.
For more information, see Mounting Instances.
Instance shape
Section titled “Instance shape”The public instance currently exposes:
root is the resolved root element the component was mounted on.
state is the public reactive state object.
Properties marked private or readonly in state options are protected from external reads and/or writes.
Updating writable public properties triggers the component update flow.
For broader guidance on reactive state behavior, see State and State Update Flow.
dispose()
Section titled “dispose()”dispose() unmounts the instance and runs cleanup behavior.
addStateListener()
Section titled “addStateListener()”Use addStateListener() to subscribe to a specific state property.
const cleanup = instance.addStateListener('count', (event) => { console.log(event.newValue);});The listener receives an event object with the following properties:
| Property | Description |
|---|---|
property | The state property name that changed. |
newValue | The incoming value for the update. |
oldValue | The outgoing value for the update. |
target | The mounted instance that emitted the change. |
The method returns a cleanup function that removes the listener.
To learn more, see State Listeners.