# nvreact

> Show NiiVue viewers in a React 19 app with @niivue/nvreact: one component for a single viewer, or a scene for a grid of them.

`@niivue/nvreact` puts NiiVue viewers in a React app. It creates the
canvas, attaches the viewer, resizes it with the page and cleans up when the
component goes away, so you only describe what to show.

## Install

**npm**

```bash
npm install @niivue/nvreact@next @niivue/niivue@next
```

**pnpm**

```bash
pnpm add @niivue/nvreact@next @niivue/niivue@next
```

**Yarn**

```bash
yarn add @niivue/nvreact@next @niivue/niivue@next
```

**Bun**

```bash
bun add @niivue/nvreact@next @niivue/niivue@next
```

You install NiiVue alongside the bindings, and your app needs React 19.

## Your first viewer

```tsx
import { NvViewer } from '@niivue/nvreact'

export function Brain() {
  return (
    <NvViewer
      volumes={[{ url: '/volumes/mni152.nii.gz' }]}
      style={{ height: 500 }}
    />
  )
}
```

The viewer fills the element it is given, so give it a height.

## Which part do you need?

- **One viewer on a page:** the `NvViewer` component. See
  [One viewer](https://niivue.com/docs/packages/nv-react/one-viewer/).
- **Several viewers in a grid**, optionally moving together: a scene. See
  [Several viewers](https://niivue.com/docs/packages/nv-react/several-viewers/).
- **Anything else NiiVue can do:** a scene hands you the NiiVue instance
  behind each viewer, and every NiiVue guide applies to it. See
  [Using NiiVue directly](https://niivue.com/docs/packages/nv-react/niivue-instance/).
