Skip to content

React Installation

Install and set up the React integration for Webgazer.ts.

Installation

bash
npm install @webgazer-ts/react @webgazer-ts/core
bash
pnpm add @webgazer-ts/react @webgazer-ts/core
bash
yarn add @webgazer-ts/react @webgazer-ts/core

TIP

Both packages are required. The React package depends on the core package.

Setup

1. Wrap Your App

Add the WebgazerProvider at the root of your app:

tsx
import { WebgazerProvider } from '@webgazer-ts/react';

function App() {
  return (
    <WebgazerProvider>
      <YourApp />
    </WebgazerProvider>
  );
}

2. Configure (Optional)

Pass configuration to the provider:

tsx
<WebgazerProvider
  config={{
    saveDataAcrossSessions: false,
    showVideo: true,
    showFaceOverlay: true
  }}
  autoStart={false} // Don't start automatically
>
  <YourApp />
</WebgazerProvider>

TypeScript

Full TypeScript support is included:

tsx
import type { GazePrediction, WebgazerConfig } from '@webgazer-ts/core';
import { useWebgazer, useGazeTracking } from '@webgazer-ts/react';

// All types are automatically inferred
const { isReady, begin } = useWebgazer();

Next Steps

Based on Webgazer.js by Brown HCI