React

Accura IDScan Plugin — React Integration Guide

This guide walks you through integrating the Accura IDScan Plugin into a React project built with Vite.

Step 1: Initialize Project

If you do not have an existing React project, scaffold one using Vite:

npm create vite@latest my-id-app -- --template react
cd my-id-app
npm install

Step 2: Install Plugin

Install the Accura IDScan Plugin package from the npm registry:

npm install accuraidscanplugin

If your project uses TypeScript, create a type declaration file at src/types.d.ts to suppress module resolution warnings:

declare module 'accuraidscanplugin';

Step 4: Implementation

Create a dedicated component file src/IDScanner.jsx (or .tsx). The following snippet shows only the plugin import and instantiation logic:


Step 5: Response Handling

When the plugin completes an ID card scan, it invokes the handleCapture callback with a payload object that may contain one or both of the following properties:

Property
Type
Description

front

string

Base64 Data URL of the front side of the ID card

back

string

Base64 Data URL of the back side of the ID card (if applicable)

What is Base64? Base64 is a binary-to-text encoding scheme that converts raw binary image data into a sequence of printable ASCII characters. Each scanned card image is delivered as a Data URL string (e.g., data:image/jpeg;base64,/9j/...), combining a MIME type prefix with the encoded image payload. Before transmitting to a server, this string must be decoded back into binary form (a Blob) to construct a valid multipart HTTP request.

The following demonstrates the base64-to-Blob conversion and API submission:


Step 6: Demo Implementation

The following is the complete, production-ready component. Copy and paste it directly into src/IDScanner.jsx. The original logic is preserved exactly as-is.


Step 7: Usage

Import and render the component in App.jsx:

Note: Remove the <StrictMode> wrapper from main.jsx or main.tsx if present, as React Strict Mode invokes lifecycle hooks twice in development, which can cause duplicate plugin initialization.


Step 8: Running the Project

Last updated