You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For errors that occur in the React lifecycle, you only need to use the `ErrorBoundary` component to wrap components that may have exceptions.
14
+
15
+
However, this solution is only suitable for client-side rendering, but it is completely helpless for errors in server-side rendering; nowadays, large-scale projects all adopt server-side rendering, so we need to find an easy-to-use application that can be applied to **isomorphic applications**. React error handling scheme.
16
+
17
+
`catch-react-error` is exactly to solve this problem, `catch-react-error` normally uses `ErrorBoundary` to wrap components when rendering on the client; when server-side rendering, use `try-catch` to wrap the `render` function, so you can Errors in the React lifecycle.
14
18
15
19
## Demo
16
20
@@ -34,119 +38,125 @@ npm run dev
34
38
35
39
## How to use
36
40
37
-
### 1.安装 catch-react-error
41
+
### 1.install catch-react-error
38
42
39
43
```sh
40
-
npm install catch-react-error --save
44
+
npm install catch-react-error --save
41
45
```
42
46
43
-
### 2.安装 ES7 Decorator babel plugin
47
+
### 2. Install ES7 Decorator babel plugin
44
48
45
-
我们采用 ES7 的 `Decorator` 语法来让代码更简洁,当然也可以采用函数的写法
49
+
We use ES7's Decorator syntax to make the code more concise, of course, you can also use the functional style.
The principle is: client-side rendering will use React 16's [Error Boundary](https://reactjs.org/blog/2017/07/26/error-handling-in-react-16.html) related functions to handle errors, and server-side use `try catch` to catch `render` errors.
90
97
91
-
### 5.使用@catchreacterror处理 FunctionComponent
98
+
### 5. Use @catchreacterrorto handle FunctionComponent
0 commit comments