question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide extra props to fallback component

See original GitHub issue

I would like to pass extra props into the fallback component.

My use case:

const _Uploader = lazy(() => import('uploader'));

type Props = { onRequestClose: () => void };
const Uploader: SFC<Props> = props => (
  <ErrorBoundary FallbackComponent={MyErrorComponent}>
    <Suspense fallback={<MyLoadingComponent {...props} />}>
      <_Uploader {...props} />
    </Suspense>
  </ErrorBoundary>
);

I want my fallback component, MyErrorComponent, to receive the prop onRequestClose, in the same way I provide it to MyLoadingComponent.

Perhaps the fallback component should be provided as a render prop instead of as a Component?

props => <ErrorBoundary fallback={
  ({ error }) => <MyErrorComponent error={error} {...props} />
} />

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
kentcdoddscommented, Apr 30, 2020

We’re implementing a new fallbackRender prop which will allow you to do whatever you’d like:

<ErrorBoundary fallbackRender={props => <YourErrorFallback {...props} your="extra props" />}>
  ...
</ErrorBoundary>
3reactions
bvaughncommented, Nov 6, 2018

What stops you from passing an inline function component currently?

const _Uploader = lazy(() => import("uploader"));

type Props = { onRequestClose: () => void };
const Uploader: SFC<Props> = props => (
  <ErrorBoundary
    FallbackComponent={({ error }) => (
      <MyErrorComponent error={error} onRequestClose={onRequestClose} />
    )}
  >
    <Suspense fallback={<MyLoadingComponent {...props} />}>
      <_Uploader {...props} />
    </Suspense>
  </ErrorBoundary>
);

Here’s an example: https://codesandbox.io/s/zk469wp6jp

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use Error Boundaries with Fallback UI in React - Medium
Error boundaries catch errors during rendering, in lifecycle methods, and in constructors of the whole tree below them.
Read more >
React error handling with react-error-boundary - LogRocket Blog
With react-error-boundary, we can simply wrap components where we expect errors with the provided ErrorBoundary component and pass in some extra ...
Read more >
How to allow fallback prop in React error boundary with ...
I have an error boundary on top of my app. It works, and I can pass it a custom component ...
Read more >
What you may not know about the Error Boundary
According to the React docs, we use static getDerivedStateFromError() to render a fallback UI after an error has been thrown. Use ...
Read more >
React.Component
The render() method is the only required method in a class component. When called, it should examine this.props and this.state and return one...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found