# Add the feedback widget to a React app

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

Mount the provider once. Then any component can open the widget, switch boards, and read whether it is open. React 19 or newer is required.

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

## Before you start

- **React 19 or newer.** The React package declares `react` and `react-dom` `^19.0.0` as peer dependencies. On React 18, use the core SDK and mount it in an effect.
- **Your organization ID.** Copy it from Settings → Widget → Installation. `FeebloProvider` takes it as a required `organizationId` prop.
- **A board for posts.** The feedback module submits to a board. Pick one with `defaultBoard`, or switch boards at runtime with `setBoard`.
- **A token for verified posts.** Optional. To attach posts to a confirmed identity, mint a JWT on your server and pass it as `token` on the `user` prop.

## Mount the provider and open the widget

Follow the steps in order. Each one leaves the app in a state you can check in the browser.

1. **Install the React package.** Install both packages. `@feeblo/sdk-react` depends on `@feeblo/sdk` and re-exports its API, so every import in this guide can come from the React package.

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

2. **Wrap your app in `FeebloProvider`.** Render the provider once, above every component that opens the widget. It initializes the widget on mount and destroys it on unmount, including StrictMode double mounts.

   ```tsx
   import { FeebloProvider } from "@feeblo/sdk-react";

   export function App() {
     return (
       <FeebloProvider organizationId="org_123" placement="bottom-right">
         <FeedbackButton />
       </FeebloProvider>
     );
   }
   ```

3. **Open the widget from a button.** Call `useFeeblo` in any component below the provider. The hook returns `open`, `close`, `openModule`, `setBoard`, `identify`, `metadata`, plus reactive `isOpen` and `isReady` values.

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

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

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

4. **Pass the signed-in user.** The `user` prop identifies the current user. A new object calls `identify` on the live widget without recreating it.

   ```tsx
   <FeebloProvider
     organizationId="org_123"
     user={{ id: user.id, email: user.email, name: user.name }}
   >
     <App />
   </FeebloProvider>
   ```

5. **Track submissions.** `useFeebloEvent` subscribes for the lifetime of the component. Write the handler inline: the hook reads it through a ref, so a new closure on each render never resubscribes.

   ```tsx
   import { useFeebloEvent } from "@feeblo/sdk-react";

   export function FeedbackAnalytics() {
     useFeebloEvent("feedbackSubmitted", (event) => {
       console.log(event.detail.data);
     });

     return null;
   }
   ```

6. **Switch modules or boards.** The hook exposes `openModule` and `setBoard` for later interactions. `openModule` only switches to modules the current config enables.

   ```tsx
   const feeblo = useFeeblo();

   feeblo.openModule("updates");
   feeblo.setBoard("roadmap");
   ```

7. **Handle errors and height changes.** `onError` receives an `EmbedError` with a stable code and message. `onHeightChange` reports the iframe height whenever it changes. Both are read through refs, so inline closures are safe.

   ```tsx
   <FeebloProvider
     organizationId="org_123"
     onError={(error) => {
       console.warn(error.code, error.message);
     }}
     onHeightChange={(height) => {
       setWidgetHeight(height);
     }}
   >
     <App />
   </FeebloProvider>
   ```

8. **Confirm the widget loaded.** Set the `debug` prop for the first run. The SDK logs a banner with your org ID and base URL, then trigger bindings and events.

   ```tsx
   <FeebloProvider organizationId="org_123" debug>
     <App />
   </FeebloProvider>
   ```

## What you should see

- **A launcher in the corner.** The `placement` prop renders a launcher 20px from the bottom corner you picked. Omit it and nothing shows until a trigger or `feeblo.open()` runs.
- **`isOpen` follows the widget.** Clicking the button opens the widget and flips `isOpen` to true. Closing it with Escape, an outside click, or the widget's own close button flips it back.
- **Posts carry the user.** A submission from an identified user lands on the board with that name and email. Only `id` is required, so an email is optional.
- **Events reach your handler.** `feedbackSubmitted` fires with the board, the post title, and any trigger metadata. The hook removes the listener when the component unmounts.

## What each prop does

Config props recreate the widget. The `user` prop does not. Callbacks are read through refs.

| Prop | Effect |
| --- | --- |
| `organizationId`, `mode`, `modules` | Tears down the widget and mounts a new one. |
| `placement`, `theme`, `locale`, `defaultBoard`, `debug`, `baseUrl`, `containerStyles` | Same: a new value recreates the widget. |
| `user` | Calls `identify` on the live widget. No remount. |
| `onClose`, `onError`, `onHeightChange` | Read through refs. Inline closures are safe. |

## Common problems

These four account for most React installs that load but do not behave.

- **`useFeeblo` throws.** The component sits outside the provider. The error reads: `[feeblo-sdk-react] useFeeblo must be used inside a <FeebloProvider>.`
- **The widget remounts on navigation.** The provider is mounted inside a route component, so it unmounts with the route. Move it to the layout above your routes.
- **The widget has the wrong user.** Setting `user` back to `undefined` does not sign anyone out. The SDK has no clear-identity API, so the last identity stays until another `identify` call or a provider remount.
- **Two widgets open at once.** One page, one integration path. A provider plus the CDN script tag creates two SDK instances that fight over the same container.

## Mount it once, above your routes

The provider owns the widget instance. Where you mount it decides how long the widget lives.

- Put the provider in your root layout or `App` component so it survives navigation.
- Keep one provider per page. Two providers mean two SDK instances and a split event stream.
- Drive the `user` prop from state. Everything else is configuration you set once.

Plain triggers still work. The provider binds DOM triggers as well as hooks, so a button with `data-feeblo-feedback` opens the widget the provider mounted:

```html
<button data-feeblo-feedback data-feeblo-plan="pro">Give feedback</button>
```

The extra attribute arrives as metadata on the post and in the `feedbackSubmitted` event.

## Where to go next

The provider and hooks are the whole React surface. The widget options and the identity token are shared with every other framework.

- Next.js: provider in a client layout, user from the server. https://feeblo.com/install/nextjs
- 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
- Roadmap: statuses fill the public lanes. https://feeblo.com/features/roadmap

## SDK docs

- Quickstart: https://docs.feeblo.com/developers/quickstart
- Every provider prop: https://docs.feeblo.com/developers/configuration
- Events and triggers: https://docs.feeblo.com/developers/triggers-and-events
- Signed identity tokens: https://docs.feeblo.com/developers/widget-sso
