# Install with Next.js

Wrap the Next.js config with withDiorama and start the app from a client component.

Next.js builds with webpack or Turbopack, not Vite. `withDiorama` writes the effect registry and its types to `src/diorama.gen.ts` and points both bundlers at it. Effects go in `src/effects/`.

## Install the packages

### npm

```sh
npm install @dioramajs/diorama three
```

### pnpm

```sh
pnpm add @dioramajs/diorama three
```

### yarn

```sh
yarn add @dioramajs/diorama three
```

### bun

```sh
bun add @dioramajs/diorama three
```

## Wrap the config

```ts title="next.config.ts"
import { withDiorama } from '@dioramajs/diorama/next'

export default withDiorama({})
```

## Start the app from a client component

```tsx title="src/app/diorama.tsx"
'use client'
import { start } from '@dioramajs/diorama'
import { useEffect } from 'react'

export function Diorama() {
  useEffect(() => void start(), [])
  return null
}
```

Render `<Diorama />` once in the root layout.

```tsx title="src/app/layout.tsx"
import type { ReactNode } from 'react'
import { Diorama } from './diorama'

export default function RootLayout({
  children,
}: {
  children: ReactNode
}) {
  return (
    <html lang="en">
      <body>
        {children}
        <Diorama />
      </body>
    </html>
  )
}
```

## Put an effect on an image

```tsx title="src/app/page.tsx"
export default function Page() {
  return (
    <img
      src="/cover.jpg"
      width={800}
      height={450}
      data-dio="ripple"
    />
  )
}
```

Commit `src/diorama.gen.ts`. In development new and removed effect files are picked up on their own, and Fast Refresh replaces an edited effect.
