Skip to content

Commit

Permalink
site: Add ErrorBoundary for live demo, ref ant-design#11553
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Aug 2, 2018
1 parent 7ec5669 commit e397c09
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
3 changes: 0 additions & 3 deletions components/slider/demo/input-number.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ class IntegerStep extends React.Component {
}

onChange = (value) => {
if (isNaN(value)) {
return;
}
this.setState({
inputValue: value,
});
Expand Down
5 changes: 4 additions & 1 deletion site/theme/template/Content/Demo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import classNames from 'classnames';
import LZString from 'lz-string';
import { Icon, Tooltip } from 'antd';
import EditButton from './EditButton';
import ErrorBoundary from './ErrorBoundary';
import BrowserFrame from '../BrowserFrame';
import { ping } from '../utils';

Expand Down Expand Up @@ -183,7 +184,9 @@ ${state.sourceCode.replace('mountNode', 'document.getElementById(\'container\')'
return (
<section className={codeBoxClass} id={meta.id}>
<section className="code-box-demo">
{this.liveDemo}
<ErrorBoundary>
{this.liveDemo}
</ErrorBoundary>
{
style
? <style dangerouslySetInnerHTML={{ __html: style }} />
Expand Down
22 changes: 22 additions & 0 deletions site/theme/template/Content/ErrorBoundary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'React';
import { Alert } from 'antd';

export default class ErrorBoundary extends React.Component {
state = {
error: null,
};

componentDidCatch(error, info) {
this.setState({ error, info });
}

render() {
const { children } = this.props;
const { error, info } = this.state;
if (error) {
// You can render any custom fallback UI
return <Alert type="error" message={error.toString()} description={info.componentStack} />;
}
return children;
}
}

0 comments on commit e397c09

Please sign in to comment.