You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
525 B
28 lines
525 B
2 years ago
|
import React, { useState } from 'react';
|
||
|
import { Alert, Button } from 'antd';
|
||
|
|
||
|
const { ErrorBoundary } = Alert;
|
||
|
const ThrowError: React.FC = () => {
|
||
|
const [error, setError] = useState<Error>();
|
||
|
const onClick = () => {
|
||
|
setError(new Error('An Uncaught Error'));
|
||
|
};
|
||
|
|
||
|
if (error) {
|
||
|
throw error;
|
||
|
}
|
||
|
return (
|
||
|
<Button danger onClick={onClick}>
|
||
|
Click me to throw a error
|
||
|
</Button>
|
||
|
);
|
||
|
};
|
||
|
|
||
|
const App: React.FC = () => (
|
||
|
<ErrorBoundary>
|
||
|
<ThrowError />
|
||
|
</ErrorBoundary>
|
||
|
);
|
||
|
|
||
|
export default App;
|