@beforequery/react gives you two ways to put your assistant inside a React app:
<BeforeQueryChat />— a polished, self-contained chat panel: streaming answers, numbered source citations, thread continuity, error states, and thumbs up/down feedback, all built in.useBeforeQueryChat— a headless hook that manages streaming, state, and errors while you own every pixel of the UI.
Set up the component
1
Install the packages
react and react-dom (>= 18) are peer dependencies.2
Get a client key
In the dashboard at app.beforequery.com, open Project → Integration Credentials and create a public client key (
bq_pk_…). Public keys are safe to ship in browsers — they’re scoped to one project and support an origin allowlist. Copy the key and your project ID.3
Embed the chat panel
4
Customize the look
Match your brand with the
theme prop, and tune the copy:Component props
Build your own UI with the hook
When the prebuilt panel doesn’t fit,useBeforeQueryChat gives you the same streaming machinery with none of the styling:
messages, ask(query), isStreaming, error, threadId, reset(), and sendFeedback(). Follow-up questions automatically continue the same thread — call reset() to start over.
Collect feedback
Assistant messages carry a server-assignedmessageId once streaming completes — use it to record ratings (1–5):
Test against a local backend
Point the component (or hook) at a locally running API withbaseUrl:
Troubleshooting
- 401/403 errors — check the client key belongs to the same project as
projectId, and that your page’s origin is on the key’s allowlist. - Captcha errors — if your project enforces reCAPTCHA, pass
getCaptchaTokenreturning a fresh v3 token per request.