> ## Documentation Index
> Fetch the complete documentation index at: https://makeswift-sasha-eng-8460-create-a-guide-for-troubleshooting.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# <ReactRuntimeProvider>

> The `<ReactRuntimeProvider>` component takes a Makeswift runtime and provides it to the [`<Page>`](/developer/reference/components/page) component for rendering snapshots.

## Props

<ParamField query="runtime" type="Runtime" required>
  A Makeswift [runtime](/developer/reference/runtime/constructor).
</ParamField>

<ParamField query="previewMode" type="boolean" required>
  When set to `true`, the preview version of a page will be rendered. See
  [example](#example) below for usage.
</ParamField>

<ParamField query="children" type="React.Node">
  The children components to render.
</ParamField>

<ParamField query="locale" type="string">
  <p>A valid locale string (ex. `"en-US"`).</p>

  <Note>This is required if your site supports
  more than one locale.</Note>
</ParamField>

## Example

<Tabs>
  <Tab title="App Router">
    The following example shows how the `<ReactRuntimeProvider>` is used to implement the `<MakeswiftProvider>` client component as outlined in step 9 of the [App Router Installation guide](/developer/app-router/installation). The `<MakeswiftProvider>` is subsequently utilized in the App Router's [root layout](https://nextjs.org/docs/app/api-reference/file-conventions/layout#root-layouts).

    <CodeGroup>
      ```tsx src/makeswift/provider.tsx
      "use client";

      import { runtime } from "@/makeswift/runtime";
      import {
        ReactRuntimeProvider,
        RootStyleRegistry,
      } from "@makeswift/runtime/next";
      import "@/makeswift/components";

      export function MakeswiftProvider({
        children,
        previewMode,
      }: {
        children: React.ReactNode;
        previewMode: boolean;
      }) {
        return (
          <ReactRuntimeProvider previewMode={previewMode} runtime={runtime}>
            <RootStyleRegistry>{children}</RootStyleRegistry>
          </ReactRuntimeProvider>
        );
      }
      ```

      ```tsx src/app/layout.tsx
      import type { Metadata } from "next";
      import { draftMode } from "next/headers";
      import { Inter } from "next/font/google";
      import { MakeswiftProvider } from "@/makeswift/provider";
      import "@/makeswift/components";
      import "./globals.css";

      const inter = Inter({ subsets: ["latin"] });

      export const metadata: Metadata = {
        title: "Create Next App",
        description: "Generated by create next app",
      };

      export default async function RootLayout({
        children,
      }: Readonly<{
        children: React.ReactNode;
      }>) {
        return (
          <html lang="en">
            <body className={inter.className}>
              <MakeswiftProvider previewMode={(await draftMode()).isEnabled}>
                {children}
              </MakeswiftProvider>
            </body>
          </html>
        );
      }
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Pages Router">
    The following example shows how to add a `<ReactRuntimeProvider>` to a [Custom App](https://nextjs.org/docs/pages/building-your-application/routing/custom-app) as outlined in step 10 of the [Pages Router Installation guide](/developer/pages-router/installation). The `previewMode` property is returned from `getStaticProps` in an optional catch-all route.

    <CodeGroup>
      ```tsx src/pages/_app.tsx
      import type { AppProps } from "next/app";
      import { ReactRuntimeProvider } from "@makeswift/runtime/next";

      import { runtime } from "@/makeswift/runtime";
      import "@/makeswift/components";

      export default function App({
        Component,
        pageProps: { previewMode, locale, ...pageProps },
      }: AppProps) {
        return (
          <ReactRuntimeProvider
            runtime={runtime}
            previewMode={previewMode}
            locale={locale}
          >
            <Component {...pageProps} />
          </ReactRuntimeProvider>
        );
      }
      ```

      ```tsx src/pages/[[...path]].tsx
      import { Makeswift } from "@makeswift/runtime/next";

      export async function getStaticProps({ params, previewData }) {
        // ...

        return {
          props: {
            // ...
            previewMode: Makeswift.getPreviewMode(previewData),
          },
        };
      }
      ```
    </CodeGroup>
  </Tab>
</Tabs>
