React
Accura Face Plugin — React Integration Guide
This guide walks you through integrating the Accura Face Plugin into a React project built with Vite.
Prerequisites
Before proceeding, ensure the following requirement is met:
accura.xml— Place youraccura.xmlfile in thepublic/folder of your project aspublic/accura.xml. This file is required by the plugin to initialize the face detection engine. You can download it from here.
The
public/directory is served as static assets in Vite-based projects, making the file accessible at runtime via the path/accura.xml.
Step 1: Initialize Project
If you do not have an existing React project, scaffold one using Vite:
npm create vite@latest my-face-app -- --template react
cd my-face-app
npm installStep 2: Install Plugin
Install the Accura Face Plugin package from the npm registry:
Step 3: TypeScript Support (Recommended)
If your project uses TypeScript, create a type declaration file at src/types.d.ts to suppress module resolution warnings and enable IDE intellisense:
Ensure this file is included in your tsconfig.app.json's include array:
Step 4: Implementation
Create a dedicated component file at src/FaceScanner.jsx (or .tsx for TypeScript). The following snippet shows only the plugin import and initialization logic:
Step 5: Response Handling
When the plugin successfully detects and captures a face, it fires the base64Handler callback. This callback receives a single argument — an object containing a base64 property. The value is a Data URL string encoding the captured face image in Base64 format (e.g., data:image/jpeg;base64,/9j/...).
What is Base64? Base64 is a binary-to-text encoding mechanism that expresses raw binary image data as a printable ASCII string. The prefix (e.g., data:image/jpeg;base64,) identifies the MIME type of the image. The remainder is the encoded pixel data, which can be directly transmitted over HTTP without binary transfer protocols.
The following handler demonstrates extracting the value and forwarding it to a remote verification endpoint:
Step 6: Demo Implementation
The following is the complete, production-ready component. Copy and paste it directly into src/FaceScanner.jsx. The original logic is preserved exactly as-is.
Step 7: Usage
Import and render the FaceScanner component in your App.jsx:
Note: Remove the
<StrictMode>wrapper frommain.jsxormain.tsxif present, as React Strict Mode invokes lifecycle hooks twice in development, which can cause duplicate plugin initialization.
Step 8: Running the Project
Last updated