Skip to content

Component Constructor

The API for the component constructor returned by defineComponent().

This constructor, along with the instances it creates, is the main API surface that consumers work with.

The component constructor creates mounted component instances.

Use the constructor when you need to create, find, or tear down instances from outside the component definition.

For the mounted instance API itself, see Component Instance.

The public constructor currently exposes:

displayName is the constructor’s public name for debugging and reporting.

This is the same value provided to name in the defineComponent() options.

Use mount() to create one component instance directly from a root element or selector.

const instance = Counter.mount('[data-counter]', { ... });

You can also pass initialState to the second argument.

For a broader comparison of mounting approaches, see Mounting Instances.

Use getInstance() when you expect the instance to exist and want absence to throw.

It identifies the instance via a direct reference to, or CSS selector for, the root element.

const instance = Counter.getInstance('[data-counter]');

For a broader guide to retrieving and working with instances, see Instance Management.

Use findInstance() when absence is a normal branch and null is acceptable.

It identifies the instance via a direct reference to, or CSS selector for, the root element.

const maybeInstance = Counter.findInstance('[data-counter]');

For a broader guide to retrieving and working with instances, see Instance Management.

Use unmount() when you want to dispose a specific instance by root reference.

It identifies the instance via a direct reference to, or CSS selector for, the root element.

Counter.unmount('[data-counter]');

For broader teardown guidance, see Instance Management.

Use unmountAll() when you want to dispose every mounted instance for the same component constructor.

Counter.unmountAll();

For broader teardown guidance, see Instance Management.