Next.js
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
<Kotick />. -
A server component cannot give a function to a client component, so it cannot give the
fixturesloader. Render<Kotick fixtures={…} />in a client component: -
Call
useMachineReduceronly in client components. A server component can import a machine file ofkotick/reducerand callmachine.reducer, for example to make the initial state from the URL. Give that state to the client component as a prop: -
Call the hooks of
kotick/xstateandcreateActorContext()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.
Pages Router
kotick also works in the Pages Router. Render <Kotick /> in pages/_app.tsx, so that it stays mounted when the page changes:
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.