@sparse-bug/react
Version:
Official React SDK for Sparse Bug, a lightweight, self-hosted error tracker.
60 lines (54 loc) • 1.93 kB
text/typescript
import { ReactNode } from 'react';
import * as react_jsx_runtime from 'react/jsx-runtime';
/**
* Configuration for the Sparse Bug client.
*/
interface SparseBugConfig {
/** Your project's unique API Key from the Sparse Bug dashboard. */
apiKey: string;
/** The API endpoint of your self-hosted or cloud Sparse Bug instance. */
endpoint: string;
/** Disables error reporting. Useful for local development. Defaults to true. */
enabled?: boolean;
}
/**
* Props for the main SparseBugProvider component.
*/
interface SparseBugProviderProps {
children: ReactNode;
config: SparseBugConfig;
/** A React component to display when a render error occurs. */
fallback?: ReactNode | ((error: Error) => ReactNode);
}
/**
* Defines the user context to enrich error reports.
*/
interface UserContext {
id?: string | number;
email?: string;
name?: string;
[key: string]: any;
}
declare class SparseBugClient {
private config;
private userContext;
constructor(config: SparseBugConfig);
/**
* Sets user information to be sent with subsequent error reports.
* @param user - An object containing user details, or null to clear.
*/
setUser(user: UserContext | null): void;
/**
* Reports an error to the Sparse Bug API.
* @param error - The Error object to report.
* @param componentStack - Optional React component stack trace.
*/
report(error: Error, componentStack?: string): void;
}
/**
* Accesses the Sparse Bug client instance to manually report errors or set user context.
* Must be used within a <SparseBugProvider>.
*/
declare const useSparseBug: () => SparseBugClient;
declare function SparseBugProvider({ children, config, fallback, }: SparseBugProviderProps): react_jsx_runtime.JSX.Element;
export { type SparseBugConfig, SparseBugProvider, type SparseBugProviderProps, type UserContext, useSparseBug };