Skip to content

Extend React ErrorBoundary component to accept render props for children #3052

@dan-overton

Description

@dan-overton

Package + Version

@sentry/react

Version:

5.27.3

Description

I'm using the Sentry ErrorBoundary as the default ErrorBoundary in my application, and want to wrap the lazy loading of a React module via React.lazy.

As per facebook/react#14254 (comment) this requires the Error Boundary to accept render props for it's children. The Sentry Error Boundary currently doesn't, but instead brings up 'Warning: Functions are not valid as a React child in React component' as any function passed in children is not called.

I've extended the Sentry ErrorBoundary locally, and added the following clause to the render method:

 if (typeof this.props.children === 'function') {
      return this.props.children();
    }

    return this.props.children;

This seemingly works well, but it would be nice to have this available in the Sentry component itself. I'm happy to provide a pull request if that would help.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions