createReactorProvider
createReactorProvider builds your reactors inside the React tree instead of at
module scope, once per mounted provider, and returns a useReactor() hook that
hands them to components with their full types. It is the setup a
server-rendered app (Next.js, or any React SSR) needs, and it replaces the
provider such apps used to write by hand.
Import
Section titled “Import”import { createReactorProvider } from "@ic-reactor/react""use client"import { createReactorProvider, defineReactor } from "@ic-reactor/react"import { canisterId, idlFactory, type _SERVICE } from "./declarations/todo"
export const { ReactorProvider, useReactor } = createReactorProvider(() => defineReactor<_SERVICE>({ name: "todo", idlFactory, canisterId }))// src/app/layout.tsx (a server component)import { ReactorProvider } from "../reactor"
export default function RootLayout({ children,}: { children: React.ReactNode}) { return ( <html lang="en"> <body> <ReactorProvider>{children}</ReactorProvider> </body> </html> )}