ctrlplusb / react-async-component

Resolve components asynchronously, with support for code splitting and advanced server side rendering use cases.
MIT License
1.45k stars 62 forks source link

Throw an error to be caught by Error Boundaries #65

Closed fuhton closed 6 years ago

fuhton commented 6 years ago

Ideally, I'd be able to through an error on the System.import that sends the content of that error to the Error Boundary component further up the tree.

resolve: () => System.import('./my/component.js').catch(e => throw e);

This is currently caught inside of the resolveModule and is used for displaying the error component, instead of being thrown in the render() cycle. Ideally, I'd be able to throw this error in the render function and utilize my parent Error Boundary to catch/display this error.

I'm not sure if this is an obvious use case, or covered by another configuration. I've thrown together a PR to show the use case either way.

fuhton commented 6 years ago

For anyone else having an issue, it's easily solved with

const ErrorComponent = ({ error }) => { throw error.error; };