Skip to main content

React usage

React integration for ThumbmarkJS - browser fingerprinting library.

Installation

npm install @thumbmarkjs/thumbmarkjs @thumbmarkjs/react

Usage

1. Wrap your app or a specific component

import { ThumbmarkProvider } from '@thumbmarkjs/react';

function App() {
return (
<ThumbmarkProvider>
<MyComponent />
</ThumbmarkProvider>
);
}

2. Use the hook

import { useThumbmark } from '@thumbmarkjs/react';

function MyComponent() {
const { thumbmark, visitorId, isLoading, error, reload } = useThumbmark();

if (isLoading) return <div>Loading...</div>;
if (error) return <div>Error: {error.message}</div>;

return (
<div>
<div>Visitor ID: {visitorId}</div>
<div>Thumbmark: {thumbmark}</div>
<button onClick={reload}>Reload</button>
</div>
);
}

With API Key

<ThumbmarkProvider apiKey="your-key">
<MyComponent />
</ThumbmarkProvider>

With Options

<ThumbmarkProvider
apiKey="your-key"
options={{
timeout: 3000,
exclude: ['webgl']
}}
>
<MyComponent />
</ThumbmarkProvider>

API

<ThumbmarkProvider>

PropTypeDescription
apiKeystringOptional API key for the hosted ThumbmarkJS API
optionsThumbmarkOptionsOptional configuration options passed to the underlying Thumbmark instance

useThumbmark()

Returns an object with the following fields:

FieldTypeDescription
thumbmarkstring | nullThe generated thumbmark hash
visitorIdstring | nullThe visitor ID (when API is used)
componentsRecord<string, any> | nullRaw fingerprint components
infoRecord<string, any> | nullAdditional info returned by the API
isLoadingbooleanLoading state
errorError | nullError state
reload() => Promise<void>Re-generate the thumbmark

The hook is SSR-safe — it only runs on the client.

See also the configuration options.