Skip to documentation

Use Pollenate with React and Next.js

Render the typed React widget, attach context and callbacks, and choose when it remounts.

Updated Read as Markdown

The package is @pollenate/react and its component is PollenateWidget. It renders the collector directly; you do not need to add the standalone widget script for the same instance.

bash
npm install @pollenate/react

Add the component

tsx
import { PollenateWidget } from '@pollenate/react';

export function Helpfulness() {
  return (
    <PollenateWidget
      apiKey="YOUR_COLLECT_ONLY_ORGANIZATION_KEY"
      inboxKey="YOUR_INBOX_KEY"
      type="thumbs"
      inline
      theme="auto"
      prompt="Was this useful?"
      context={{ feature: 'documentation', article: 'quickstart' }}
      stripQueryParams
      onSubmit={(event) => {
        console.log('Saved feedback ID:', event.detail.id);
      }}
    />
  );
}

apiKey and inboxKey are required. The key must be an organization collection key. The onSubmit callback receives a CustomEvent with the saved feedback in event.detail; onImpression receives the impression event.

Next.js App Router

Put the widget in a Client Component:

tsx
'use client';

import { PollenateWidget } from '@pollenate/react';

export function ProductFeedback() {
  const apiKey = process.env.NEXT_PUBLIC_POLLENATE_COLLECT_KEY;
  const inboxKey = process.env.NEXT_PUBLIC_POLLENATE_INBOX_KEY;
  if (!apiKey || !inboxKey) return null;

  return <PollenateWidget apiKey={apiKey} inboxKey={inboxKey} type="stars" />;
}

Variables prefixed NEXT_PUBLIC_ are public browser configuration. Only place a collect-only organization key there. Keep privileged credentials on your server.

Useful props

Props Purpose
type, prompt Choose the scale and question
inline, position Render in the component location or choose a floating position
theme light, dark or system-following auto
context Attach your own product, route or release context
trackImpressions Enable/disable impression tracking; default is true
stripQueryParams Omit page query parameters from tracking
primaryColor, bgColor, textColor, borderColor Override appearance
buttonText, successMessage, commentPlaceholder Customize messages
onSubmit, onImpression React callbacks for widget events

For inline use, place the component where it should render and set inline. The compatibility container prop also enables inline mode; the React component renders in its React tree rather than moving itself into a DOM element selected by that string.

Route changes and verification

The widget tracks an impression once per mounted instance. If each route needs a fresh prompt and impression, remount deliberately with a React key, such as the current route. Keep a stable key when you want the same instance to survive navigation; avoid keying it to every render.

Use real route context from your app, submit a test event, and verify the destination inbox. If the widget fails, check the same key, scope, brand and CSP requirements as the standalone script. For a completely different interface, use custom UI.