Skip to content
Botscent

React

Add the page half of Botscent to a React app without a framework and check the install.

Add Botscent to a React app that has no framework, such as a Vite app. The page half runs in the browser from the <Botscent /> component. The server half runs in the server for your pages or your API. For a Next.js app, see Next.js.

Before you start

You need:

  • React 18 or 19.
  • Node.js 22.12 or later.

1. Install the package

Install botscent from npm.

Terminal
npm install botscent

With pnpm, yarn or bun, use their add command.

2. Add the page half

In src/main.tsx, render <Botscent /> from botscent/react once, next to your root component.

src/main.tsx
import { createRoot } from 'react-dom/client'
import { Botscent } from 'botscent/react'
import { App } from './App.tsx'

createRoot(document.getElementById('root')!).render(
  <>
    <Botscent />
    <App />
  </>,
)

The page half now starts when <Botscent /> mounts, and the component renders nothing.

3. Add the server half

A React app without a framework runs only in the browser. Add the server half to the server for your pages or your API. Use the page for that server:

4. Read the verdict

In any component, call useBotscent from botscent/react. The component renders again when the page verdict changes.

src/App.tsx
import { useBotscent } from 'botscent/react'

export function App() {
  const verdict = useBotscent()
  return <pre>{JSON.stringify(verdict)}</pre>
}

In a normal browser, the component shows {"type":"human","reasons":[]}.

Warning: Do not use the page verdict to allow access. The visitor's browser computes the page verdict. On your server, use isVerified on the request's own verdict, as The trust model describes.

5. Check the install

Start the dev server. Then run the check against its URL.

Terminal
npx botscent check http://localhost:5173/

The page-script check prints pass, and the command exits with code 0.

The server-half check prints unknown, because the dev server has no server half. If a check fails, see Verify your install.

Next steps