# Next.js
Use kotick in the App Router, with server components, and in the Pages Router.
`kotick` and `kotick/xstate` start with `'use client'`, so you can import them in the App Router.
`kotick/reducer` has no directive, so any module can import a machine file, also a server component or a route handler. Only client components call `useMachineReducer`.
## Server components
- A server component can render ``.
- A server component cannot give a function to a client component, so it cannot give the `fixtures` loader. Render `` in a client component:
```tsx
// src/components/dev-tools.tsx
'use client';
import { Kotick } from 'kotick';
const fixtures = process.env.NODE_ENV !== 'production' ? () => import('@/debug/fixtures') : undefined;
export function DevTools() {
return ;
}
```
- Call `useMachineReducer` only in client components. A server component can import a machine file of `kotick/reducer` and call `machine.reducer`, for example to make the initial state from the URL. Give that state to the client component as a prop:
```tsx
// src/app/feedback/page.tsx
import { FeedbackForm } from '@/components/feedback-form';
import { type FeedbackState, feedbackMachine, ratingOf } from '@/machines/feedback';
const start: FeedbackState = { status: 'rating' };
export default async function FeedbackPage({ searchParams }: PageProps<'/feedback'>) {
const rating = ratingOf((await searchParams).rating);
const initial = rating ? feedbackMachine.reducer(start, { type: 'RATE', rating }) : start;
return ;
}
```
- Call the hooks of `kotick/xstate` and `createActorContext()` only in client components, as with `@xstate/react`.
- On the server, kotick does nothing: the overlay renders nothing, and nothing registers. The overlay mounts after hydration, so it does not cause hydration errors.
## Root layout
Render the overlay in the root layout, after `{children}`. The root layout stays mounted when the page changes. Thus, the panel stays open while the machines of each page register and unregister.
```tsx
// src/app/layout.tsx
import type { ReactNode } from 'react';
import { DevTools } from '@/components/dev-tools';
export default function RootLayout({ children }: { children: ReactNode }) {
return (
{children}
);
}
```
## Pages Router
kotick also works in the Pages Router. Render `` in `pages/_app.tsx`, so that it stays mounted when the page changes:
```tsx
// src/pages/_app.tsx
import type { AppProps } from 'next/app';
import { Kotick } from 'kotick';
const fixtures = process.env.NODE_ENV !== 'production' ? () => import('@/debug/fixtures') : undefined;
export default function App({ Component, pageProps }: AppProps) {
return (
<>
>
);
}
```
The Pages Router has no server components. Thus, `_app.tsx` can give the `fixtures` loader, and each page and component can call the hooks of both adapters. During server rendering, kotick does nothing, as in the App Router.