Preact
Copy as MarkdownQuick start
Section titled “Quick start”-
Install the player.
Terminal window npm i @rupamotion/player -
Put
hero.rupaplay(export as Player file in Rupamotion) inpublic/. -
Import the element and use it in a component:
import "@rupamotion/player/element";export function Hero() {return <rupa-player src="/hero.rupaplay"></rupa-player>;}For TypeScript, declare
rupa-playerinJSX.IntrinsicElements.
That’s it: the animation plays.
This demo loads a .rupaplay file: it plays once JavaScript runs.
Need control?
Section titled “Need control?”The element’s player is the player once the file is mounted (null before). Keep the element in a ref:
import "@rupamotion/player/element";import type { RupaPlayerElement } from "@rupamotion/player/element";import { useRef } from "preact/hooks";
export function Hero() { const el = useRef<RupaPlayerElement>(null); return ( <> <rupa-player ref={el} src="/hero.rupaplay"></rupa-player> <button onClick={() => el.current?.player?.pause()}>Pause</button> </> );}See Control playback and Events.