Skip to content

Commit b6e1247

Browse files
committed
refactor: Remove unused ErrorBoundary component and update imports in Example and Startup screens
1 parent 9ab8fab commit b6e1247

File tree

12 files changed

+77
-52
lines changed

12 files changed

+77
-52
lines changed

documentation/docs/04-Guides/08 - Components/03 - ErrorBoundary.md

Lines changed: 0 additions & 37 deletions
This file was deleted.
File renamed without changes.

documentation/docs/04-Guides/08 - Components/06 - DefaultError.md renamed to documentation/docs/04-Guides/08 - Components/04 - DefaultError.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ id: default-error
66
keywords: [DefaultError, Error, boundary]
77
---
88

9-
The molecule `DefaultError` component is used into the `SafeScreen` component as the default error UI.
9+
The molecule `DefaultError` component is used into the [`ErrorBoundary` component](/docs/components/error-boundary) as the default error UI.
1010
This component is composed of `Text` components and a `Button` to reset the error (for re-executing the query for example).
1111

1212
### Props
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
slug: /components/error-boundary
3+
sidebar_label: ErrorBoundary
4+
title: ErrorBoundary
5+
id: error-boundary
6+
keywords: [ErrorBoundary, Error, boundary]
7+
---
8+
9+
The organism `ErrorBoundary` component is a helper component that allows you to catch JavaScript errors anywhere in the component tree and log those errors. This component is particularly useful when you need to catch errors in your app and display a fallback UI to the user.
10+
11+
### Usage
12+
13+
```jsx
14+
import { ErrorBoundary } from "@/components/atoms";
15+
16+
<ErrorBoundary fallback={<div>Something went wrong</div>}>
17+
<ExampleApplication />
18+
</ErrorBoundary>
19+
```
20+
21+
### Log errors
22+
In the `ErrorBoundary` component, you will find a `onErrorReport` function that allows you to log the error in your application. You can use any logging library to log the error like `sentry`, `logrocket`, `crashlytics`, etc.
23+
24+
```jsx
25+
const onErrorReport = (error: Error, info: ErrorInfo) => {
26+
// use any crash reporting tool here
27+
return onError?.(error, info);
28+
};
29+
```
30+
31+
### Props
32+
33+
As the `ErrorBoundary` component is a wrapper component, it accepts all the props from the [`react-error-boundary`](https://github.com/bvaughn/react-error-boundary) library with fallback props except that the `fallback` prop is empty by default.
34+
35+
| Name | Type | Default | Description |
36+
|------------|--------|---------|-----------------------------------------------------------------------------------------------|
37+
| fallback | ReactNode | | The required fallback UI to be displayed when an error occurs. |
38+
| onReset | function | | The optional function to reset the error state |
39+
| ...props | any | | all props from `ErrorBoundary` component are supported. |
40+
41+
42+
:::info
43+
This component is used in the `SafeScreen` component to catch JavaScript errors and display a fallback UI to the user.
File renamed without changes.

template/eslint.config.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { dirname } from 'node:path';
22
import { fileURLToPath } from 'node:url';
3-
import tsEslint from 'typescript-eslint';
43
import importPlugin from 'eslint-plugin-import';
54
import jest from 'eslint-plugin-jest';
65
import react from 'eslint-plugin-react';
76
import reactHooks from 'eslint-plugin-react-hooks';
87
import typescriptSortKeys from 'eslint-plugin-typescript-sort-keys';
98
import unicorn from 'eslint-plugin-unicorn';
109
import unusedImports from 'eslint-plugin-unused-imports';
10+
import tsEslint from 'typescript-eslint';
1111

1212
const __filename = fileURLToPath(import.meta.url);
1313
const __dirname = dirname(__filename);
@@ -56,6 +56,13 @@ export default [
5656
'react/jsx-sort-props': 2,
5757
'react/prop-types': 2,
5858
'react/react-in-jsx-scope': 0,
59+
'react/require-default-props': [
60+
2,
61+
{
62+
forbidDefaultForRequired: true,
63+
functions: 'defaultArguments',
64+
},
65+
],
5966
'unicorn/better-regex': 2,
6067
'unicorn/catch-error-name': 2,
6168
'unicorn/consistent-empty-array-spread': 2,
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export { default as AssetByVariant } from './AssetByVariant/AssetByVariant';
2-
export { default as ErrorBoundary } from './ErrorBoundary/ErrorBoundary';
32
export { default as IconByVariant } from './IconByVariant/IconByVariant';
43
export { default as Skeleton } from './Skeleton/Skeleton';

template/src/components/molecules/DefaultError/DefaultError.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type Props = {
1010
onReset?: () => void;
1111
};
1212

13-
function DefaultErrorScreen({ onReset }: Props) {
13+
function DefaultErrorScreen({ onReset = undefined }: Props) {
1414
const { gutters, layout, colors, fonts } = useTheme();
1515
const { t } = useTranslation();
1616
const { resetBoundary } = useErrorBoundary();

template/src/components/atoms/ErrorBoundary/ErrorBoundary.tsx renamed to template/src/components/organisms/ErrorBoundary/ErrorBoundary.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@ import type { ErrorInfo } from 'react';
22
import type { ErrorBoundaryPropsWithFallback } from 'react-error-boundary';
33

44
import { ErrorBoundary as DefaultErrorBoundary } from 'react-error-boundary';
5-
import { View } from 'react-native';
5+
6+
import { DefaultError } from '@/components/molecules';
67

78
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
89

9-
type Props = Optional<ErrorBoundaryPropsWithFallback, 'fallback'>;
10+
type Props = Optional<ErrorBoundaryPropsWithFallback, 'fallback'> & {
11+
onReset?: () => void;
12+
};
1013

11-
function ErrorBoundary({ fallback = <View />, onError, ...props }: Props) {
14+
function ErrorBoundary({
15+
fallback = undefined,
16+
onReset = undefined,
17+
onError,
18+
...props
19+
}: Props) {
1220
const onErrorReport = (error: Error, info: ErrorInfo) => {
1321
// use any crash reporting tool here
1422
return onError?.(error, info);
@@ -17,7 +25,7 @@ function ErrorBoundary({ fallback = <View />, onError, ...props }: Props) {
1725
return (
1826
<DefaultErrorBoundary
1927
{...props}
20-
fallback={fallback}
28+
fallback={fallback || <DefaultError onReset={onReset} />}
2129
onError={onErrorReport}
2230
/>
2331
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as ErrorBoundary } from './ErrorBoundary/ErrorBoundary';

0 commit comments

Comments
 (0)