@stoplight/react-error-boundary
v3.0.0
Published
<!-- BADGES -->
Downloads
248,087
Readme
@stoplight/react-error-boundary
The React error boundary tailored to Stoplight needs, inspired by react-error-boundary.
Features
- all the great features provided by react-error-boundary,
- built-in error reporting powered by Sentry,
- supports recovering,
- fallback component can try to recover error boundary.
Installation
Supported in modern browsers and node.
# latest stable
yarn add @stoplight/react-error-boundary
Usage
You can either make use of:
- withErrorBoundary HOC
import { withErrorBoundary } from '@stoplight/react-error-boundary';
const SchemaViewer: React.FunctionComponent<{ schema: unknown }> = ({ schema }) => {
if (typeof schema !== 'object' || schema === null) {
throw new Error('Schema must be an object');
}
if (Object.keys(schema).length === 0) {
throw new Error('Schema cannot be empty');
}
return <span>This is fine.</span>;
};
const MyWrappedComponent = withErrorBoundary(SchemaViewer, {
recoverableProps: ['schema'],
});
const Page = () => (
<div>
<h1>Schema Viewer</h1>
<MyWrappedComponent schema={{}} />
</div>
);
- ErrorBoundary component
import { ErrorBoundary } from '@stoplight/react-error-boundary';
const SchemaViewer: React.FunctionComponent<{ schema: unknown }> = ({ schema }) => {
if (typeof schema !== 'object' || schema === null) {
throw new Error('Schema must be an object');
}
if (Object.keys(schema).length === 0) {
throw new Error('Schema cannot be empty');
}
return <span>This is fine.</span>;
};
const Page = () => (
<div>
<h1>Schema Viewer</h1>
<ErrorBoundary>
<SchemaViewer schema={{}} />
</ErrorBoundary>
</div>
);
Contributing
- Clone repo.
- Create / checkout
feature/{name}
,chore/{name}
, orfix/{name}
branch. - Install deps:
yarn
. - Make your changes.
- Run tests:
yarn test.prod
. - Stage relevant files to git.
- Commit:
yarn commit
. NOTE: Commits that don't follow the conventional format will be rejected.yarn commit
creates this format for you, or you can put it together manually and then do a regulargit commit
. - Push:
git push
. - Open PR targeting the
master
branch.