Next.js
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/. -
Render the component in a page. The App Router needs no
"use client"here:@rupamotion/player/reactis already a client module, andsrcandmarkupare plain strings a Server Component can pass.app/page.tsx import { RupaPlayer } from "@rupamotion/player/react";export default function Page() {return <RupaPlayer src="/hero.rupaplay" markup="auto" />;}
That’s it: the animation plays after hydration.
This demo loads a .rupaplay file: it plays once JavaScript runs.
Need control?
Section titled “Need control?”A ref, a hook or a callback prop (onReady, onError) needs a client component, so the file starts with
"use client":
"use client";import { useRef } from "react";import { RupaPlayer, usePlayerState } from "@rupamotion/player/react";import type { Player } from "@rupamotion/player";
export function Hero() { const player = useRef<Player>(null); const { paused } = usePlayerState(player); return ( <> <RupaPlayer ref={player} src="/hero.rupaplay" markup="auto" /> <button onClick={() => (paused ? player.current?.play() : player.current?.pause())}> {paused ? "Play" : "Pause"} </button> </> );}See Control playback and Events.
In a client component
Section titled “In a client component”The text you put inside renders on the server; the motion starts after hydration. Put the .rupaplay file in public/.
"use client";import { RupaPlayer } from "@rupamotion/player/react";
export default function Hero() { return <RupaPlayer src="/hero.rupaplay" markup="auto" />;}See React for the hooks and server rendering.