# Add the feedback widget to a Next.js app

Canonical: https://feeblo.com/install/nextjs Markdown mirror of: https://feeblo.com/install/nextjs

The App Router splits your tree into server and client components. The widget belongs in one client provider at the root, so every route shares one instance.

Try it: https://app.feeblo.com

## Before you start

- **The App Router.** This guide uses the `app` directory, a root layout, and client components. The Pages Router setup matches the React guide instead.
- **React 19 or newer.** The React bindings declare `react` and `react-dom` `^19.0.0` as peer dependencies. Check your Next.js version's React release before you start.
- **Your organization ID.** Copy it from Settings → Widget → Installation. The provider takes it as a required `organizationId` prop.
- **A way to read the current user.** Your layout or a server component needs the signed-in user's id, email, and name to pass down.

## Add the widget to the App Router

The order matters. The client provider exists before the layout imports it, and the layout exists before any page calls the hooks.

1. **Install the packages.** Install the React bindings with the core SDK. Both are ESM packages with no runtime dependencies.

   ```bash
   npm install @feeblo/sdk @feeblo/sdk-react
   ```

2. **Create a client provider component.** Add `use client` to the top of a new file. The provider runs effects, so it has to be a Client Component.

   ```tsx
   "use client";

   import { FeebloProvider, type UserIdentity } from "@feeblo/sdk-react";
   import type { ReactNode } from "react";

   export function FeebloWidgetProvider({
     children,
     user,
   }: {
     children: ReactNode;
     user?: UserIdentity;
   }) {
     return (
       <FeebloProvider
         organizationId="org_123"
         placement="bottom-right"
         user={user}
       >
         {children}
       </FeebloProvider>
     );
   }
   ```

3. **Wrap the root layout.** Render the provider inside `body` in `app/layout.tsx`. The root layout stays mounted across route changes, so the widget mounts once. If your app already has a providers file, nest `FeebloWidgetProvider` inside it rather than adding a second wrapper.

   ```tsx
   import type { ReactNode } from "react";
   import { FeebloWidgetProvider } from "./feeblo-provider";

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

4. **Add a trigger in a client component.** The `useFeeblo` hook only works below the provider and inside a client component. Add `use client` to any file that calls it.

   ```tsx
   "use client";

   import { useFeeblo } from "@feeblo/sdk-react";

   export function FeedbackButton() {
     const feeblo = useFeeblo();

     return (
       <button type="button" onClick={() => feeblo.open()}>
         Give feedback
       </button>
     );
   }
   ```

5. **Pass the user from the server.** Read the session in the layout and pass plain values to the provider. A new user object calls `identify` on the live widget without remounting it. The values below come from your auth setup; only `id` is required.

   ```tsx
   <FeebloWidgetProvider
     user={{ id: user.id, email: user.email, name: user.name }}
   >
     {children}
   </FeebloWidgetProvider>
   ```

6. **Mint a token on the server when you need one.** A signed token proves the identity. Sign a JWT on your server with your organization secret and the claims the widget expects, then pass it as `token` alongside the `id`. The browser never sees the secret. Widget SSO documents the claims and the signing call: https://docs.feeblo.com/developers/widget-sso

7. **Confirm the widget loaded.** Add `debug` to the provider for the first run. The SDK prints a banner with the org ID and base URL, then every trigger binding and event.

   ```tsx
   <FeebloProvider organizationId="org_123" debug user={user}>
     {children}
   </FeebloProvider>
   ```

## What you should see

- **A launcher on every route.** The provider sits in the root layout, so the launcher appears on every page without repeating the component.
- **No remount on client navigation.** Layouts persist across App Router navigation. Moving between pages keeps the same widget instance and the same identified user.
- **The widget mounts after hydration.** The provider initializes in an effect, so the server-rendered HTML arrives first and the launcher appears once React takes over.
- **Posts carry the server identity.** A submission lands on the board with the id, email, and name your layout passed down, plus a verified contact when you send a token.

## App Router rules that matter

Four boundaries decide whether the widget mounts correctly.

- **`use client` on the provider file.** The provider uses state and effects. Server Components cannot run them.
- **Provider in `app/layout.tsx`.** Layouts persist. A provider inside a page unmounts on the next navigation.
- **Plain values across the boundary.** Props passed from a Server Component must serialize. Send strings, numbers, and booleans.
- **Secret stays on the server.** Sign the identity token in a route handler or server action and pass only the token.

## Where each file sits

Only two files carry the client boundary. Pages stay server components. The provider accepts every widget option as a prop, so `mode`, `modules`, `theme`, `locale`, and `defaultBoard` live on the same component. Set them once in the client file.

| File | Kind | Role |
| --- | --- | --- |
| `app/layout.tsx` | Server Component | Reads the session and renders the provider around children. |
| `app/feeblo-provider.tsx` | Client Component | Owns the widget and passes `organizationId` and config props. |
| `app/feedback-button.tsx` | Client Component | Calls `useFeeblo` to open the widget. |
| `app/page.tsx` | Server Component | Renders the button. No widget code needed. |

## Common problems

Each of these comes from the server and client split, not from the widget.

- **The hook only works in a Client Component.** Next.js refuses the import. Add `use client` to the file that renders the provider.
- **The widget remounts on navigation.** The provider lives in a page, not the layout. Move it up to `app/layout.tsx`.
- **`useFeeblo` throws on the server.** The hook ran during server rendering. Call it in a Client Component that renders only in the browser tree.
- **Two widgets fight.** The layout loads the CDN script and the provider. Remove the script tag. One page, one integration path.

## Where to go next

The widget behaves the same on every framework once it mounts. The difference is where the client boundary sits.

- React: the hooks and props reference. https://feeblo.com/install/react
- All install paths: React, Next.js, Vue, and plain HTML. https://feeblo.com/install
- Feedback boards: votes, comments, tags, and moderation. https://feeblo.com/features/feedback
- Changelog: announce what shipped, on a schedule. https://feeblo.com/features/changelog

## SDK docs

- Quickstart: https://docs.feeblo.com/developers/quickstart
- Every provider prop: https://docs.feeblo.com/developers/configuration
- The identity object: https://docs.feeblo.com/developers/identity
- Signing identity tokens: https://docs.feeblo.com/developers/widget-sso
