Skip to content

Commit

Permalink
Added error handling for rendering (fixes #715).
Browse files Browse the repository at this point in the history
  • Loading branch information
radekmie committed May 2, 2020
1 parent 04e1ff4 commit 759a0a7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions website/components/Playground/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import { parseQuery, updateQuery } from './utils';
import { themes } from '../universal';

class Playground extends Component {
static getDerivedStateFromError(error) {
return { error };
}

constructor() {
super(...arguments);

Expand Down Expand Up @@ -46,7 +50,7 @@ class Playground extends Component {
}));
}

this.setState({ [key]: value });
this.setState({ error: undefined, [key]: value });
}

render() {
Expand All @@ -66,7 +70,11 @@ class Playground extends Component {
<PlaygroundPropsField name="props" spellCheck={false} />
</section>

<PlaygroundPreviewField name="props" nameTheme="theme" />
{this.state.error ? (
<pre children={'' + this.state.error} />
) : (
<PlaygroundPreviewField name="props" nameTheme="theme" />
)}
</PlaygroundForm>
);
}
Expand Down

0 comments on commit 759a0a7

Please sign in to comment.