# usePlayerState

> `const` **usePlayerState**: <`S`>(`source`) => [`PlayerView`](/reference/api/rupamotion/player/react/interfaces/playerview/)<`S`>

The player's state for a UI: the component renders again at each `statechange`, `play` and `pause` of the player.

## Type Parameters

### S

`S` _extends_ `string` = `string`

## Parameters

### source

[`PlayerSource`](/reference/api/rupamotion/player/react/type-aliases/playersource/)<`S`>

The ref given to `<RupaPlayer ref>`, or the player `useRupaPlayer` returns (see `PlayerSource`).

## Returns

[`PlayerView`](/reference/api/rupamotion/player/react/interfaces/playerview/)<`S`>

`{ player, state, paused }` (see `PlayerView`).

## Example

```tsx
import { useRef } from "react";
import type { Player } from "@rupamotion/player";
import { RupaPlayer, usePlayerState } from "@rupamotion/player/react";

export function Controls() {
	const ref = useRef<Player>(null);
	const { player, state, paused } = usePlayerState(ref);
	return (
		<>
			<RupaPlayer ref={ref} src="/hero.rupaplay" markup="auto" />
			<p>Playing: {state ?? "none"}</p>
			<button disabled={!player} onClick={() => (paused ? player?.play() : player?.pause())}>
				{paused ? "Play" : "Pause"}
			</button>
		</>
	);
}
```
