Error boundary catches errors of child components
See original GitHub issueExpected behavior
An error thrown by a child of the intersection observer should end up in the user deifned error boundary that was placed outside of the intersection observer.
Current behavior
The intersection observer catches all errors, istead of only handling a missing DOM node situation.
Steps to reproduce
Render an app like this:
import React from 'react';
import IntersectionObserver from '@researchgate/react-intersection-observer';
class MyErrorBoundary extends React.Component {
state = {hasError: false};
componentDidCatch(error, info) {
console.log('I am not called!');
}
static getDerivedStateFromError(error) {
return {hasError: true};
}
render() {
console.log('I am called?');
return this.state.hasError ? 'oy' : this.props.children;
}
}
class ChildWithError extends React.Component {
render() {
return (
<button
onClick={() => {
this.setState(() => {
throw new Error('Some forbidden Button was clicked! ');
});
}}
>
click here to trigger error
</button>
);
}
}
class App extends React.Component {
render() {
return (
<MyErrorBoundary>
<IntersectionObserver onChange={() => {}} threshold={0.5}>
<div>
<ChildWithError />
</div>
</IntersectionObserver>
</MyErrorBoundary>
);
}
}
You will find the console.log('I am not called!'); is not called.
Context (environment)
- Version: 1.1.0 / 1.1.1
- Platform: Darwin host 18.7.0 Darwin Kernel Version 18.7.0: Thu Jan 23 06:52:12 PST 2020; root:xnu-4903.278.25~1/RELEASE_X86_64 x86_64
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
React error handling with react-error-boundary - LogRocket Blog
Error boundaries were introduced in React 16 as a way to catch and handle JavaScript errors that occur in the UI parts of...
Read more >Handle errors in React components like a pro
Error boundaries are React components that catch JavaScript errors anywhere in their child component tree, log those errors, and display a ...
Read more >Error boundaries vs. try...catch - Educative.io
Error boundaries are React components capable of catching JavaScript errors anywhere in their child component tree. They log those errors and display a ......
Read more >How to Handle Errors in React - AppSignal Blog
React Error boundaries are great for catching errors in declarative code (e.g., inside their child component tree). · For other cases, you need ......
Read more >Catching Errors in React with Error Boundaries
The idea behind error boundaries is that you can wrap any part of your application in a special component – a so-called error...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

https://github.com/researchgate/react-intersection-observer/releases/tag/v1.1.3
That is a great way to use this. Thank you!