useRupaPlayer
Copy as Markdown
constuseRupaPlayer: <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.
Type Parameters
Section titled “Type Parameters”S extends string = string
Parameters
Section titled “Parameters”RefObject<Element | null>
A ref to the export’s root element (the one with data-rupa).
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.
Returns
Section titled “Returns”Player<S> | null
The Player; null before it is mounted, on a server, or without an element in ref (the development
build warns).
Example
Section titled “Example”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> );}