Enjoying the docs? Start building free, no credit card needed. Get started →
Docs / Next.js

Web

Next.js

A floating button that opens your feature board in a sheet. Your API key never reaches the browser.

Needs Next.js 14 or later with the App Router, React 18 or later, and Node 20 or later.

Set up

  1. Install the package

    npm install @fewchurs/next

    1.7.2 is the latest version.

  2. Add your API key

    Put the key in your environment file. Don't start the name with NEXT_PUBLIC_, or it will be sent to the browser.

    .env.local
    FEWCHURS_API_KEY=fr_live_xxx
  3. Add the route handler

    Create this one file. When a visitor votes, comments or adds a request, the sheet calls this route. The route adds your key and passes the call to Fewchurs.

    app/api/fewchurs/[...route]/route.ts
    export { GET, POST, DELETE } from "@fewchurs/next/handler";
  4. Add the floating button

    Add it to your root layout, so it shows on every page.

    app/layout.tsx
    import { FewchursButton } from "@fewchurs/next";import "@fewchurs/next/styles.css";export default function RootLayout({ children }) {  return (    <html lang="en">      <body>        {children}        <FewchursButton floating />      </body>    </html>  );}

    A Feedback button now stays on the bottom right of every page. Pressing it slides in your feature board as a sheet, or from the bottom on phones. Inside the sheet, New request shows only the form, and Comments and Notify me open in a popup. A popup closes with its × button, Escape, or a click outside it.

    The board only loads when someone presses the button, and the button doesn't make your pages dynamic.

The sheet as described here needs @fewchurs/next 1.7.0 or later. To upgrade, run npm install @fewchurs/next@latest.

Change the look

Pass your own label as the button's text. Use floating="left" for the bottom left, or leave out floating to place the button anywhere in your page. Every other prop goes to the board in the sheet: which tabs to show, whether people can comment, and your colors and text. You can also use CSS variables like --fw-primary, --fw-radius and --fw-font.

<FewchursButton  floating="left"  tabs={["top", "new"]}  defaultTab="top"  allowComments  emailField="optional"  theme={{ primary: "#0f766e", radius: 8 }}  labels={{ title: "Ideas", submit: "Suggest an idea" }}>  Suggest an idea</FewchursButton>

className and style go on the button itself.

Need functions as props, like renderFeature? Those can't be passed to a server component. Use FewchursButton from @fewchurs/react in a "use client" file instead, with <FewchursProvider baseUrl="/api/fewchurs"> around it.

Use a full page board

Want the board on its own page instead of in a sheet? Use FewchursBoard. You need the same API key and route handler from Set up.

app/feedback/page.tsx
import { FewchursBoard } from "@fewchurs/next";import "@fewchurs/next/styles.css";export default function FeedbackPage() {  return <FewchursBoard />;}

This board loads on the server, so the page arrives with the requests already in it. Search engines can read them too. It takes the same board props as the button:

<FewchursBoard  tabs={["top", "new"]}  theme={{ primary: "#0f766e", radius: 8 }}  labels={{ title: "Ideas" }}/>

initialFeatureId shows one request above the list, with its comments open and rendered on the server — handy for a link from an email straight to a request. See Link to one request.

Signed-in users

By default each visitor gets a random ID, saved in a cookie. If your app has accounts, use a hash of the user's ID instead. Then votes follow the person to every device.

app/api/fewchurs/[...route]/route.ts
import { createHandler } from "@fewchurs/next/handler";import { createHash } from "node:crypto";export const { GET, POST, DELETE } = createHandler({  deviceId: async () => {    const session = await auth(); // your own auth    return session      ? createHash("sha256").update(session.userId).digest("hex")      : crypto.randomUUID();  },});
Always hash the ID. Never send a raw user ID or an email address.

Build your own UI

Use the React hooks in a client component. Point the provider at your route handler and the key still stays on the server.

"use client";import { FewchursProvider, useFeatures } from "@fewchurs/react";function Ideas() {  const { features, loadMore, hasMore } = useFeatures({ sort: "top" });  // your own markup}export function Feedback() {  // Talks to your route handler, so the key stays on the server  return (    <FewchursProvider baseUrl="/api/fewchurs">      <Ideas />    </FewchursProvider>  );}

Every hook is listed in the React guide.

Localhost and going live

Your API key only works from the domain you add to your app. Next.js handles this for you. The package reads the domain from each request and sends it to Fewchurs. This applies to @fewchurs/next 1.1.0 and later.

While you build on localhost

You only need your API key. There is nothing to add in the dashboard yet. localhost and 127.0.0.1 always work.

When you go live

  1. Open your app in the Fewchurs dashboard.

  2. Under Where does your app run? pick Web.

  3. Add just the domain in Website domain, like yourcompany.com. Leave out https://.

  4. Click Save changes. A new domain can take up to a minute to work.

  5. Add FEWCHURS_API_KEY to the environment variables on your host, then deploy.

  6. Press the button on your live site. You should see your requests.

Don't skip the domain. The sheet can work on localhost and still be refused on your live site if your domain isn't added. If you're upgrading from an older version, add it before you deploy the upgrade.

Test your domain before you go live

You can check your domain from localhost:

  1. Add this line to your .env.local:

    .env.local
    FEWCHURS_APP_ID=yourcompany.com
  2. Restart your dev server and press the button.

If you see your requests your domain is set up. Remove the line when you're done. If you only just added the domain and it's refused, wait a minute and reload.

Which addresses work

If you add yourcompany.com:

Your site runs onResult
http://localhost:3000Works
https://yourcompany.comWorks
https://www.yourcompany.comWorks
https://app.yourcompany.comWorks
https://othercompany.comRefused
https://yourapp.vercel.appRefused

Subdomains of the domain you add work on their own. It doesn't work the other way: if you add app.yourcompany.com then yourcompany.com is refused. Add the main domain if you use more than one.

When you need FEWCHURS_APP_ID

Most sites don't need it. It replaces the domain the package reads from the request. Use it when your site runs on an address you didn't add, for example a preview deployment:

FEWCHURS_APP_ID=yourcompany.com

To set the ID in code instead, the floating button only needs it on the route handler. A full page board needs it in both places:

// app/api/fewchurs/[...route]/route.tsexport const { GET, POST, DELETE } = createHandler({ appId: "docs.yourcompany.com" });// app/feedback/page.tsx<FewchursBoard appId="docs.yourcompany.com" />

If something goes wrong

When a call is refused, the sheet shows Invalid API key. If the domain is the cause, the line under it and your server log both name it:

[fewchurs] This API key is not set up for yourcompany.com. Add it to your app in the Fewchurs dashboard.

Add that domain in the dashboard. If the domain in the message is wrong, set FEWCHURS_APP_ID. If the log doesn't mention a domain, copy your key from the dashboard into your environment variables and deploy again.

The "Powered by" badge

The free plan shows a small "Powered by Fewchurs" line. It goes away on its own when you upgrade to Starter or Pro.

Stuck? If the sheet says "Fewchurs isn't set up", FEWCHURS_API_KEY is missing on the server. Restart your dev server after adding it. If it says "Couldn't load requests", check that the route file is at app/api/fewchurs/[...route]/route.ts, or src/app/api/... if your app uses a src folder.