Skip to main content

Initializes the server-rendered components of a page on the client.

mountAll mounts every instance of a component, mount one instance you pick by its rootId. Both read the props from the hydration data the server wrote.

Call mountAll in your entry file. Its first argument is namespace:name: the Fluid namespace your component collection is registered under (see Getting Started), followed by the component's name:

mountAll calls your callback once per accordion on the page. new Accordion(props) stores the props. init() builds the state machine, renders and starts it, and returns the instance, so the callback can return it directly. Read instance.machine, instance.api and instance.hydrator after init(), an earlier read throws.

The namespace is required because two component collections can register a component with the same name, and mountAll and mount throw without it.

mountAll mounts every instance on its own. To mount one yourself, for example to pass callbacks, set autoMount="{false}" on the root:

Then call mount with the rootId. It mounts that instance whatever its autoMount value:

When the rootId is mounted already, mount returns that instance and does not call your callback. So you can export the instance from a module, and a second run of that module still gets the one instance. To mount the rootId again, for example with other props, call destroy() on the instance first. getComponentInstance and destroyComponentsWithin find an instance from mount like one from mountAll.

Mounts every instance of a component that is not mounted yet and was not rendered with autoMount="{false}". It is safe to call more than once, e.g. after lazily inserted DOM adds new instances: mounted ones are skipped.

The props in the callback are typed from componentName via HydrationPropsFor. A component without generated types gets an untyped bag.

NameDescriptionRequiredDefault
componentNameK
The namespaced name, e.g. ui:select.
Yes
-
callback(data: { autoMount: boolean; props: HydrationPropsFor<Extract<K, string>>; createHydrator: () => ComponentHydrator; }) => Component<unknown, unknown> | void
Creates the instance of one hydration entry and returns it.
Yes
-

Mounts one instance by its rootId, also one that was rendered with autoMount="{false}". Like mountAll(), it skips an instance that is already mounted: it returns that one and does not call callback, so a script that runs twice still gets one instance. To mount it again, call destroy() on it first. getComponentInstance() and destroyComponentsWithin() find it like any other.

The props in the callback are typed like those of mountAll().

NameDescriptionRequiredDefault
componentNameK
The namespaced name, e.g. ui:dialog.
Yes
-
rootIdstring
The rootId the component was rendered with.
Yes
-
callback(data: { autoMount: boolean; props: HydrationPropsFor<Extract<K, string>>; createHydrator: () => ComponentHydrator; }) => T | void
Creates the instance and returns it.
Yes
-

Returns T | undefined. The instance, the one already mounted, or undefined if there is no hydration entry for rootId.

Finds a component instance that is already mounted, by the namespaced name it was mounted with and its hydration id (the id prop it was rendered with). Works for instances from mountAll() and mount() alike. It is for primitives that compose two independent instances of themselves at runtime, e.g. the submenus of a Menu.

NameDescriptionRequiredDefault
componentNamestring
The namespaced name, e.g. ui:menu.
Yes
-
idstring
The hydration id of the instance.
Yes
-

Returns T | undefined. The instance, or undefined if none is mounted under that id.

Destroys every mounted instance whose root element is root or inside it, and forgets it, its hydration data included. Call it before you remove a subtree from the DOM, e.g. a row of a FieldArray.

Only the root part of an instance counts. A component without one, such as Dialog, is never matched.

NameDescriptionRequiredDefault
rootElement | Document
The element that is about to be removed.
Yes
-