# mount

> `const` **mount**: <`S`>(`root`, `data?`, `options?`) => [`Player`](/reference/api/rupamotion/player/interfaces/player/)<`S`>

Mounts a player on an exported root and returns it (`root.rupa` holds it too).

With `data`, the table is checked first: a part that fails is left out (the development build warns), a table of an
unknown version is ignored. Without `data`, the page's `<script type="application/json" data-rupa-data="<class>">`
whose class the root has is read; without one the player controls the root's animations alone, with no state. A root
that a player holds already (of this copy of the player or another) returns that player.

## Type Parameters

### S

`S` _extends_ `string` = `string`

## Parameters

### root

`Element`

The export's root element (the one with `data-rupa`).

### data?

[`PlayerDataInput`](/reference/api/rupamotion/player/type-aliases/playerdatainput/)

The flow's table (`PlayerData`, e.g. imported from the export's `<base>.player.json`); none to read it
from the page.

### options?

`Readonly`<`Record`<`never`, `never`>>

None yet.

## Returns

[`Player`](/reference/api/rupamotion/player/interfaces/player/)<`S`>

The root's player. Only when reading `data` itself throws (a hostile getter) is nothing mounted: `undefined`.

## Throws

When `root` is not an object. Nothing else throws: an internal error makes the player inert.

## Example

```ts
import { mount } from "@rupamotion/player";
import data from "./hero.player.json";

const player = mount<"idle" | "hover">(document.querySelector(".hero")!, data);
player.on("statechange", ({ state }) => console.log(state));
```
