@codeserk/forge-stats-react
v0.7.0
Published
React plugin for Forge Stats. Error boundary and root error handlers that track errors with their component stack.
Maintainers
Readme
@codeserk/forge-stats-react
React plugin for @codeserk/forge-stats. It re-exports the whole core client, so a React app imports this package alone. The core is a peer dependency, installed with it by npm 7+, so the app always has a single client. Uncaught errors already reach captureGlobalErrors; the React tools add their component stack and the errors React error boundaries catch. Every tool is optional, pick the ones you need.
Installation
npm install @codeserk/forge-stats-reactUsage
Create the plugin, pass it to init, then use the tools you need. They report through the client init created:
import { captureGlobalErrors, init, reactPlugin } from '@codeserk/forge-stats-react'
export const react = reactPlugin()
init({ sdk: 'YOUR_SDK_KEY', appVersion: '1.2.3', plugins: [react] })
captureGlobalErrors()Error boundary
Any React version. Tracks the errors of its children as handled and renders the fallback:
<react.ErrorBoundary fallback={(error) => <Oops message={error.message} />}>
<App />
</react.ErrorBoundary>Root error handlers
React 19. Tracks every uncaught error and every error a boundary caught, logs it with console.error as React does, then calls your handler:
createRoot(container, {
onUncaughtError: react.errorHandler(),
onCaughtError: react.errorHandler(showErrorToast),
}).render(<App />)Your own boundary
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
react.captureError(error, errorInfo)
}A tool used before the plugin is set up by init only warns.
