Skip to content

Error boundary example fix #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -623,19 +623,37 @@ export const withErrorBoundary = <BaseProps extends InjectedProps>(
<details><summary><i>Click to expand</i></summary><p>

```tsx
import * as React from 'react';
import React, {useState} from 'react';

import { withErrorBoundary } from '../hoc';
import { ErrorMessage } from '../components';

const ErrorMessageWithErrorBoundary =
withErrorBoundary(ErrorMessage);

const BrokenButton = () => (
<button type="button" onClick={() => { throw new Error(`Catch me!`); }}>
{`Throw nasty error`}
</button >
);
const BrokenComponent = () => {
throw new Error('I\'m broken! Don\'t render me.');
};

const BrokenButton = () => {
const [shouldRenderBrokenComponent, setShouldRenderBrokenComponent] =
useState(false);

if (shouldRenderBrokenComponent) {
return <BrokenComponent />;
}

return (
<button
type="button"
onClick={() => {
setShouldRenderBrokenComponent(true);
}}
>
{`Throw nasty error`}
</button>
);
};

export default () => (
<ErrorMessageWithErrorBoundary>
Expand Down
30 changes: 24 additions & 6 deletions playground/src/hoc/with-error-boundary.usage.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
import * as React from 'react';
import React, {useState} from 'react';

import { withErrorBoundary } from '../hoc';
import { ErrorMessage } from '../components';

const ErrorMessageWithErrorBoundary =
withErrorBoundary(ErrorMessage);

const BrokenButton = () => (
<button type="button" onClick={() => { throw new Error(`Catch me!`); }}>
{`Throw nasty error`}
</button >
);
const BrokenComponent = () => {
throw new Error('I\'m broken! Don\'t render me.');
};

const BrokenButton = () => {
const [shouldRenderBrokenComponent, setShouldRenderBrokenComponent] =
useState(false);

if (shouldRenderBrokenComponent) {
return <BrokenComponent />;
}

return (
<button
type="button"
onClick={() => {
setShouldRenderBrokenComponent(true);
}}
>
{`Throw nasty error`}
</button>
);
};

export default () => (
<ErrorMessageWithErrorBoundary>
Expand Down