diff --git a/README.md b/README.md index 5e130e8..0d9e914 100644 --- a/README.md +++ b/README.md @@ -623,7 +623,7 @@ export const withErrorBoundary = (
Click to expand

```tsx -import * as React from 'react'; +import React, {useState} from 'react'; import { withErrorBoundary } from '../hoc'; import { ErrorMessage } from '../components'; @@ -631,11 +631,29 @@ import { ErrorMessage } from '../components'; const ErrorMessageWithErrorBoundary = withErrorBoundary(ErrorMessage); -const BrokenButton = () => ( - -); +const BrokenComponent = () => { + throw new Error('I\'m broken! Don\'t render me.'); +}; + +const BrokenButton = () => { + const [shouldRenderBrokenComponent, setShouldRenderBrokenComponent] = + useState(false); + + if (shouldRenderBrokenComponent) { + return ; + } + + return ( + + ); +}; export default () => ( diff --git a/playground/src/hoc/with-error-boundary.usage.tsx b/playground/src/hoc/with-error-boundary.usage.tsx index 3045b75..772fa50 100644 --- a/playground/src/hoc/with-error-boundary.usage.tsx +++ b/playground/src/hoc/with-error-boundary.usage.tsx @@ -1,4 +1,4 @@ -import * as React from 'react'; +import React, {useState} from 'react'; import { withErrorBoundary } from '../hoc'; import { ErrorMessage } from '../components'; @@ -6,11 +6,29 @@ import { ErrorMessage } from '../components'; const ErrorMessageWithErrorBoundary = withErrorBoundary(ErrorMessage); -const BrokenButton = () => ( - -); +const BrokenComponent = () => { + throw new Error('I\'m broken! Don\'t render me.'); +}; + +const BrokenButton = () => { + const [shouldRenderBrokenComponent, setShouldRenderBrokenComponent] = + useState(false); + + if (shouldRenderBrokenComponent) { + return ; + } + + return ( + + ); +}; export default () => (