Skip to content

Commit 74cc4c5

Browse files
committed
Catch error in Preview Wrapper
1 parent 57d4348 commit 74cc4c5

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/rsg-components/Preview/Preview.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default class Preview extends Component {
8989

9090
const exampleComponent = this.evalInContext(compiledCode);
9191
const wrappedComponent = (
92-
<Wrapper>
92+
<Wrapper onError={err => this.handleError(err)}>
9393
<PreviewComponent component={exampleComponent} />
9494
</Wrapper>
9595
);

src/rsg-components/Wrapper/Wrapper.js

+5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ import PropTypes from 'prop-types';
44
export default class Wrapper extends Component {
55
static propTypes = {
66
children: PropTypes.node.isRequired,
7+
onError: PropTypes.func.isRequired,
78
};
89

10+
componentDidCatch(error) {
11+
this.props.onError(error);
12+
}
13+
914
render() {
1015
return this.props.children;
1116
}

0 commit comments

Comments
 (0)