Skip to content

useRupaPlayer

Copy as Markdown

const useRupaPlayer: <S>(ref, data?) => Player<S> | null

Mounts the player on the element of ref after the render, for markup written in JSX, and destroys it on unmount. The element and the table are read once, when it mounts: another element needs a new key.

S extends string = string

RefObject<Element | null>

A ref to the export’s root element (the one with data-rupa).

PlayerDataInput

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

Player<S> | null

The Player; null before it is mounted, on a server, or without an element in ref (the development build warns).

import { useRef } from "react";
import { useRupaPlayer } from "@rupamotion/player/react";
import data from "./card.player.json";
export function Card() {
const root = useRef<HTMLDivElement>(null);
const player = useRupaPlayer<"idle" | "open">(root, data);
return (
<div ref={root} className="card" data-rupa="">
<button onClick={() => player?.play("open")}>Open</button>
</div>
);
}