Skip to content

React SPA example #46

@TomRadford

Description

@TomRadford

Would be awesome to have an example for a React SPA (ie: no metaframework/ssr) to document the usage of Sentry.reactErrorHandler as per https://docs.sentry.io/platforms/javascript/guides/react/#step-3-capture-react-errors

For this example in particular, would be keen to see how you recommend logging caught and recoverable errors in dev, since the example link above seems to obfuscate these errors, ie is this appropriate or would it re-log errors?

  onUncaughtError: Sentry.reactErrorHandler((error, errorInfo) => {
    console.warn("Uncaught error", error, errorInfo.componentStack);
  }),
  // Callback called when React catches an error in an ErrorBoundary.
  onCaughtError: Sentry.reactErrorHandler((error, errorInfo) => {
    // this is not in above guide
    console.warn("Caught error", error, errorInfo.componentStack);
  }),
  // Callback called when React automatically recovers from errors.
  onRecoverableError: Sentry.reactErrorHandler((error, errorInfo) => {
    // this is not in above guide
    console.warn("Recoverable error", error, errorInfo.componentStack);
  }),

The current react-router example assumes that you're in framework-mode:
https://github.com/getsentry/sentry-javascript-examples/tree/main/apps/react-router
which doesnt seem to be applicable for a SPA?

Keen to clear this up, thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions