@embrace-io/react-native
Version:
A React Native wrapper for the Embrace SDK
45 lines (44 loc) • 1.8 kB
TypeScript
/**
* Component Error API
*
* Provides automatic logging of React component rendering errors that include
* a component stack trace. This is used internally by the SDK's global error
* handler to capture additional context about where in the React tree an error occurred.
*
* @see {@link https://embrace.io/docs/react-native/features/render-errors | Render Errors Documentation}
*/
import { ErrorInfo } from "react";
/**
* An Error that includes React's `componentStack` property, indicating it originated
* from a React component rendering failure.
*/
type ComponentError = Error & ErrorInfo;
/**
* Logs errors with additional React component stack information if available.
*
* This function checks if the provided error is a React Native rendering error
* (i.e., it includes a `componentStack` property). If the `componentStack` is
* present and non-empty the error details are logged using
* `EmbraceManagerModule.logMessageWithSeverityAndProperties`, including the message
* and the component stack trace.
*
* NOTES
* - The `componentStack` provides a trace of the React component tree at the time
* of the error but does not include line or column numbers.
* - This function is complementary to other logging mechanisms that capture more
* detailed stack traces, including line and column numbers.
*
* Example `componentStack` trace:
* ```
* in App
* in RCTView
* in Unknown
* in AppContainer
* ```
*
* @param error - The error object to be checked and logged.
* @returns A promise that resolves to `true` if the error was logged, or `false`
* if the error was not a React Native rendering error or the `componentStack` was empty.
*/
declare const logIfComponentError: (error: Error) => Promise<boolean>;
export { logIfComponentError, ComponentError };