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.

Catch errors inside render

See original GitHub issue

This is something I demoed in my React Europe talk but have not released yet.

Basically when you make a mistake inside render, React Hot Loader can catch the error and display a “red screen of death” inline instead of crashing your app:

screen shot 2015-07-20 at 19 21 34

There is a PR to React Hot API which is exactly what I showed at the conf, but before turning this into an officially supported feature, I want to make it more extensible. I want to make the error renderer customizable because we want to support React Native too. Some projects may want to make custom renderers that display the error on top of body instead on inline, etc.

Ideally it would be opt in, and the API would be something like react-hot-loader?reporter=npm-module-name where npm-module-name is some package that exports a React (or React Native) <Reporter> component as a default export. This component will be used as <Reporter error={e} /> by React Hot Loader, when specified.

Here is an example of such component by @KeywordBrain: https://github.com/KeywordBrain/redbox-react.

If somebody wants to take a stab at it, please do! (But let us know in this thread.)

If not, I’ll get around to implementing this in August.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:19 (10 by maintainers)

github_iconTop GitHub Comments

4reactions
gaearoncommented, Apr 18, 2016

With React Hot Loader 3, we now have error reporting on initial mount. It doesn’t work for updates yet but I think it should once facebook/react#6020 lands. Keeping this issue open to track this.

0reactions
gregbergecommented, Oct 10, 2017
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error Boundaries - React
Error boundaries do not catch errors inside event handlers. React doesn't need error boundaries to recover from errors in event handlers. Unlike the...
Read more >
How to Handle Errors in React - AppSignal Blog
Error boundaries catch errors during rendering, in lifecycle methods, and in constructors of the whole tree below them.
Read more >
reactjs try catch in render does not catch children errors
I'm trying to add error catching to the render function of a component. This works fine when I throw an error in the...
Read more >
React error handling with react-error-boundary - LogRocket Blog
So error boundaries only catch errors that occur in a lifecycle method, render method, and inside Hooks like useEffect .
Read more >
How to handle errors in React | InfoWorld
JavaScript errors are those which occur in the code and can be handled with standard try/catch blocks, while render errors occur in the...
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