I have the written the following function to render an error page when the top level component I wish to render encounters an error:
function unsafeRender(callback) {
try {
var renderedComponent = callback();
retu renderedComponent;
} catch(err) {
retu (<ErrorPage error={err} />);
}
}
The top level container has this method called in its render() method:
render: function() {
retu unsafeRender(function() {
retu <Component />;
});
}
When the render method of the <Component /> throws an error, it does not get caught by the unsafeRender function. Only when I apply it to the component directly does the method get called. See this fiddle for the source code.
Why is this the case and do I really have to apply such a method to every child component in order for it to work instead of being able to use it once in a top level container?
