{"schemaVersion":1,"title":"React setup","url":"https://appgram.dev/docs/guides/sdks/react","markdownUrl":"https://appgram.dev/docs/format-md/guides/sdks/react.md","jsonUrl":"https://appgram.dev/docs/agent/pages/guides/sdks/react.json","version":"current","locale":"en","markdown":"# React setup\n\nReact and Next.js setup with loading, errors, styling, and project context.\n\nUse `@appgram/react` for React and Next.js applications. Start with the headless hook below, then choose the prebuilt components when you want AppGram's interface.\n\n## Install\n\nReact 18+ and React DOM 18+ are peer dependencies. In an existing React application:\n\n```bash\nnpm install @appgram/react@0.2.5\n```\n\n## Show feedback and cast a vote\n\nCopy this into a component file and replace the project values. The provider supplies configuration to every AppGram hook and component below it. This example uses your application's HTML and styles.\n\n```tsx\n'use client';\n\nimport { AppgramProvider, useAppgramContext, useVote, useWishes, type Wish } from '@appgram/react';\n\nfunction FeedbackVote({ wish }: { wish: Wish }) {\n  const { fingerprint } = useAppgramContext();\n  const { hasVoted, voteCount, isLoading, error, vote } = useVote({\n    wishId: wish.id,\n    initialVoteCount: wish.vote_count,\n    initialHasVoted: wish.has_voted,\n  });\n\n  return (\n    <div>\n      <button\n        onClick={() => void vote()}\n        disabled={!fingerprint || isLoading || hasVoted}\n        aria-pressed={hasVoted}\n      >\n        {hasVoted ? 'Voted' : isLoading ? 'Saving…' : 'Vote'} ({voteCount})\n      </button>\n      {!fingerprint && <span> Preparing anonymous voting…</span>}\n      {error && <p role=\"alert\">{error}</p>}\n    </div>\n  );\n}\n\nfunction Feedback() {\n  const { wishes, isLoading, error, refetch } = useWishes();\n\n  if (isLoading) return <p>Loading feedback…</p>;\n  if (error) return (\n    <div>\n      <p role=\"alert\">{error}</p>\n      <button onClick={() => void refetch()}>Try again</button>\n    </div>\n  );\n  if (wishes.length === 0) return <p>No feature requests yet.</p>;\n\n  return (\n    <ul>{wishes.map((wish) => (\n      <li key={wish.id}>\n        <h2>{wish.title}</h2>\n        <FeedbackVote wish={wish} />\n      </li>\n    ))}</ul>\n  );\n}\n\nexport default function App() {\n  return (\n    <AppgramProvider config={{\n      projectId: 'YOUR_PROJECT_ID',\n      orgSlug: 'your-org',\n      projectSlug: 'your-project',\n    }}>\n      <Feedback />\n    </AppgramProvider>\n  );\n}\n```\n\nFirst create and approve `Feedback integration check` using [Getting started](/guides/getting-started#3-add-one-visible-feature-request). Replace the project values, then confirm that request appears in the list. Cast a vote and refresh the dashboard to verify the saved count.\n\nThe button waits for the provider's anonymous fingerprint, shows vote errors, and disables after a successful vote. If you disable fingerprint initialization, this example cannot cast anonymous votes. Read [customer identity](/guides/client-identity) before choosing another identification workflow.\n\nA successful empty list is different from a failed request. Check the selected project, approval, and filters if your sample is missing. Follow the complete [signup-to-feedback walkthrough](/guides/getting-started) when setting up a new workspace.\n\n## Next.js App Router\n\nKeep `'use client'` at the top of the file that uses the provider and hooks. Render this client component from your page or layout. Do not add a management API key to a `NEXT_PUBLIC_` variable or to provider configuration.\n\n## Prebuilt components and styles\n\nThe package also exports `WishList`, `RoadmapBoard`, `HelpCenter`, `Releases`, `SupportForm`, and other components. They use Tailwind utility classes; the package does not ship a standalone stylesheet.\n\nIf your application uses Tailwind CSS 3, preserve your existing configuration and include the package's compiled files and preset:\n\n```js\n// tailwind.config.cjs — merge these entries into your existing config\nmodule.exports = {\n  presets: [require('@appgram/react/tailwind-preset')],\n  content: [\n    './src/**/*.{js,ts,jsx,tsx}',\n    './node_modules/@appgram/react/dist/**/*.{js,mjs}',\n  ],\n};\n```\n\nThe preset supplies AppGram color and animation tokens; content scanning supplies the utility styles. If your build uses a different Tailwind version, use that version's package-source registration rules. The headless hooks let you keep your own styling system.\n\n## Project configuration\n\n`projectId` is required. Supply `orgSlug` and `projectSlug` for public URL and release routing. `apiUrl` can select your own API deployment; it defaults to `https://api.appgram.dev`.\n\nAnonymous fingerprinting is enabled by default and can be disabled with `enableFingerprinting: false`. Read [Customer identity and client credentials](/guides/client-identity) before choosing that behavior.\n\nContinue with the [React reference](/react-sdk), [pagination and errors](/guides/api-requests), or [troubleshooting guide](/guides/troubleshooting).\n\n","contentLocale":"en","isFallback":false,"authorship":{"authors":[],"contributors":[],"reviewedBy":[]}}