@fingerprintjs/fingerprintjs-pro-react
Version:
FingerprintJS Pro React SDK
110 lines (104 loc) • 4.32 kB
TypeScript
/**
* FingerprintJS Pro React v2.7.0 - Copyright (c) FingerprintJS, Inc, 2025 (https://fingerprint.com)
* Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
*/
import * as react from 'react';
import { PropsWithChildren } from 'react';
import { VisitorData, FingerprintJSPro, GetOptions, FpjsClientOptions } from '@fingerprintjs/fingerprintjs-pro-spa';
export { Agent, CacheLocation, CacheStub, Cacheable, FingerprintJSPro, FpjsClient, FpjsClientOptions, GetOptions, ICache, InMemoryCache, LoadOptions, LocalStorageCache, SessionStorageCache, VisitorData, defaultEndpoint, defaultScriptUrlPattern, defaultTlsEndpoint } from '@fingerprintjs/fingerprintjs-pro-spa';
import * as react_jsx_runtime from 'react/jsx-runtime';
interface QueryResult<TData, TError = Error> {
/**
* Stores current query data
* */
data?: TData;
/**
* Is true while query is loading
* */
isLoading?: boolean;
/**
* Stores current query error
* */
error?: TError;
}
interface VisitorQueryResult<TExtended extends boolean> extends QueryResult<VisitorData<TExtended>> {
data?: VisitorData<TExtended>;
}
interface GetDataOptions<TExtended extends boolean> extends FingerprintJSPro.GetOptions<TExtended> {
/**
* When set to true, the visitor data will always be fetched from our API.
* */
ignoreCache?: boolean;
}
interface VisitorQueryContext<TExtended extends boolean> extends VisitorQueryResult<TExtended> {
/**
* Performs identification request to server and returns visitors data.
* */
getData: (getDataOptions?: GetDataOptions<TExtended>) => Promise<VisitorData<TExtended>>;
}
/**
* The FingerprintJS Context
*/
interface FpjsContextInterface<TExtended extends boolean> {
getVisitorData: (config?: GetOptions<TExtended>, ignoreCache?: boolean) => Promise<VisitorData<TExtended>>;
clearCache: () => void;
}
declare const FpjsContext: react.Context<FpjsContextInterface<any>>;
interface CustomAgent {
load: (options: FingerprintJSPro.LoadOptions) => Promise<FingerprintJSPro.Agent>;
}
interface FpjsProviderOptions extends FpjsClientOptions {
/**
* If set to `true`, will force FpjsClient to be rebuilt with the new options. Should be used with caution
* since it can be triggered too often (e.g. on every render) and negatively affect performance of the JS agent.
*/
forceRebuild?: boolean;
customAgent?: CustomAgent;
}
/**
* @example
* ```jsx
* <FpjsProvider
* loadOptions = {{
* apiKey: "<your-fpjs-public-api-key>"
* }}
* cacheTime={60 * 10}
* cacheLocation={CacheLocation.LocalStorage}
* >
* <MyApp />
* </FpjsProvider>
* ```
*
* Provides the FpjsContext to its child components.
*
* @privateRemarks
* This is just a wrapper around the actual provider.
* For the implementation, see `ProviderWithEnv` component.
*/
declare function FpjsProvider<T extends boolean>(props: PropsWithChildren<FpjsProviderOptions>): react_jsx_runtime.JSX.Element;
type UseVisitorDataOptions<TExtended extends boolean> = GetDataOptions<TExtended>;
/**
* @example
* ```js
* const {
* // Request state
* data,
* isLoading,
* error,
* // A method to be called manually when the `immediate` field in the config is set to `false`:
* getData,
* } = useVisitorData({ extended: true }, { immediate: false });
* ```
* Use the `useVisitorData` hook in your components to perform identification requests with the FingerprintJS API. The returned object contains information about loading status, errors, and visitor.
*
* @param getOptions options for the `fp.get()` request
* @param config config for the hook
*/
declare function useVisitorData<TExtended extends boolean>(getOptions?: UseVisitorDataOptions<TExtended>, config?: UseVisitorDataConfig): VisitorQueryContext<TExtended>;
interface UseVisitorDataConfig {
/**
* Determines whether the `getData()` method will be called immediately after the hook mounts or not
*/
immediate: boolean;
}
export { type CustomAgent, FpjsContext, type FpjsContextInterface, FpjsProvider, type FpjsProviderOptions, type GetDataOptions, type QueryResult, type UseVisitorDataConfig, type UseVisitorDataOptions, type VisitorQueryContext, type VisitorQueryResult, useVisitorData };