# Next.js

Use RupaPlayer in a Next.js client component: the text renders on the server and the motion starts after hydration.

## Quick start

1. Install the player.

   ```sh
   npm i @rupamotion/player
   ```

2. Put `hero.rupaplay` (export as **Player file** in Rupamotion) in `public/`.

3. Render the component in a page. The App Router needs no `"use client"` here: `@rupamotion/player/react` is already a
   client module, and `src` and `markup` are plain strings a Server Component can pass.

   ```tsx
   // 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.

## Need control?

A `ref`, a hook or a callback prop (`onReady`, `onError`) needs a client component, so the file starts with
`"use client"`:

```tsx
// app/hero.tsx
"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](/guides/control/) and [Events](/guides/events/).

## In a client component

The text you put inside renders on the server; the motion starts after hydration. Put the `.rupaplay` file in `public/`.

```tsx
"use client";
import { RupaPlayer } from "@rupamotion/player/react";

export default function Hero() {
	return <RupaPlayer src="/hero.rupaplay" markup="auto" />;
}
```

See [React](/frameworks/react/) for the hooks and [server rendering](/guides/server-rendering/).
