I am using errorboundaries in my code and when I use it in the file where I am rendering my main layout components it works, Eg.:
<ErrorBoundary>
<header></header>
</ErrorBoundary>
<ErrorBoundary>
<main/> //this component has an error
</ErrorBoundary>
<ErrorBoundary>
<footer></footer>
</ErrorBoundary>
The above code works and the fallback UI is shown for the error that is in the main component. But when I use errorboundary component inside the main component file it does not work,
Eg of errorboundary that does not work:
class main extends React.Component {
//code
<ErrorBoundary>
{object}
</ErrorBoundary>
//more code
This does not work and the whole app crashes instead, displaying only a blank page. Why might this be happening and how to deal with it? Thank you.
ErrorBoundryshould do the job. And also please note that Error boundaries do not catch errors for some errors.{object}is and displaying the fallback UI it is still replacing the whole componentmainwith the fallback UI.maincomponent with the fallback UI instead of only the section of the screen where{object}is rendered<ErrorComponent/>it worked. Thank you for your help