react-error-boundary 2.2.2 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +125 -16
- package/dist/react-error-boundary.cjs.js +44 -15
- package/dist/react-error-boundary.esm.js +33 -8
- package/dist/react-error-boundary.umd.js +41 -13
- package/dist/react-error-boundary.umd.js.map +1 -1
- package/dist/react-error-boundary.umd.min.js +1 -1
- package/dist/react-error-boundary.umd.min.js.map +1 -1
- package/index.d.ts +4 -0
- package/package.json +11 -9
package/README.md
CHANGED
|
@@ -28,6 +28,12 @@ This component provides a simple and reusable wrapper that you can use to wrap
|
|
|
28
28
|
around your components. Any rendering errors in your components hierarchy can
|
|
29
29
|
then be gracefully handled.
|
|
30
30
|
|
|
31
|
+
Reading this blog post will help you understand what react-error-boundary does
|
|
32
|
+
for you:
|
|
33
|
+
[Use react-error-boundary to handle errors in React](https://kentcdodds.com/blog/use-react-error-boundary-to-handle-errors-in-react)
|
|
34
|
+
– How to simplify your React apps by handling React errors effectively with
|
|
35
|
+
react-error-boundary
|
|
36
|
+
|
|
31
37
|
## Table of Contents
|
|
32
38
|
|
|
33
39
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
@@ -38,14 +44,7 @@ then be gracefully handled.
|
|
|
38
44
|
- [Error Recovery](#error-recovery)
|
|
39
45
|
- [API](#api)
|
|
40
46
|
- [`ErrorBoundary` props](#errorboundary-props)
|
|
41
|
-
- [`
|
|
42
|
-
- [`FallbackComponent`](#fallbackcomponent)
|
|
43
|
-
- [`fallbackRender`](#fallbackrender)
|
|
44
|
-
- [`fallback`](#fallback)
|
|
45
|
-
- [`onError`](#onerror)
|
|
46
|
-
- [`onReset`](#onreset)
|
|
47
|
-
- [`resetKeys`](#resetkeys)
|
|
48
|
-
- [`onResetKeysChange`](#onresetkeyschange)
|
|
47
|
+
- [`useErrorHandler(error?: Error)`](#useerrorhandlererror-error)
|
|
49
48
|
- [Issues](#issues)
|
|
50
49
|
- [🐛 Bugs](#-bugs)
|
|
51
50
|
- [💡 Feature Requests](#-feature-requests)
|
|
@@ -190,13 +189,13 @@ specific scenario.
|
|
|
190
189
|
|
|
191
190
|
### `ErrorBoundary` props
|
|
192
191
|
|
|
193
|
-
|
|
192
|
+
#### `children`
|
|
194
193
|
|
|
195
194
|
This is what you want rendered when everything's working fine. If there's an
|
|
196
195
|
error that React can handle within the children of the `ErrorBoundary`, the
|
|
197
196
|
`ErrorBoundary` will catch that and allow you to handle it gracefully.
|
|
198
197
|
|
|
199
|
-
|
|
198
|
+
#### `FallbackComponent`
|
|
200
199
|
|
|
201
200
|
This is a component you want rendered in the event of an error. As props it will
|
|
202
201
|
be passed the `error`, `componentStack`, and `resetErrorBoundary` (which will
|
|
@@ -205,7 +204,7 @@ when used in combination with the `onReset` prop).
|
|
|
205
204
|
|
|
206
205
|
This is required if no `fallback` or `fallbackRender` prop is provided.
|
|
207
206
|
|
|
208
|
-
|
|
207
|
+
#### `fallbackRender`
|
|
209
208
|
|
|
210
209
|
This is a render-prop based API that allows you to inline your error fallback UI
|
|
211
210
|
into the component that's using the `ErrorBoundary`. This is useful if you need
|
|
@@ -247,7 +246,7 @@ problem.
|
|
|
247
246
|
|
|
248
247
|
This is required if no `FallbackComponent` or `fallback` prop is provided.
|
|
249
248
|
|
|
250
|
-
|
|
249
|
+
#### `fallback`
|
|
251
250
|
|
|
252
251
|
In the spirit of consistency with the `React.Suspense` component, we also
|
|
253
252
|
support a simple `fallback` prop which you can use for a generic fallback. This
|
|
@@ -262,12 +261,12 @@ const ui = (
|
|
|
262
261
|
)
|
|
263
262
|
```
|
|
264
263
|
|
|
265
|
-
|
|
264
|
+
#### `onError`
|
|
266
265
|
|
|
267
266
|
This will be called when there's been an error that the `ErrorBoundary` has
|
|
268
267
|
handled. It will be called with two arguments: `error`, `componentStack`.
|
|
269
268
|
|
|
270
|
-
|
|
269
|
+
#### `onReset`
|
|
271
270
|
|
|
272
271
|
This will be called immediately before the `ErrorBoundary` resets it's internal
|
|
273
272
|
state (which will result in rendering the `children` again). You should use this
|
|
@@ -279,7 +278,7 @@ error happening again.
|
|
|
279
278
|
**Important**: `onReset` will _not_ be called when reset happens from a change
|
|
280
279
|
in `resetKeys`. Use `onResetKeysChange` for that.
|
|
281
280
|
|
|
282
|
-
|
|
281
|
+
#### `resetKeys`
|
|
283
282
|
|
|
284
283
|
Sometimes an error happens as a result of local state to the component that's
|
|
285
284
|
rendering the error. If this is the case, then you can pass `resetKeys` which is
|
|
@@ -289,11 +288,121 @@ then it will reset automatically (triggering a re-render of the `children`).
|
|
|
289
288
|
|
|
290
289
|
See the recovery examples above.
|
|
291
290
|
|
|
292
|
-
|
|
291
|
+
#### `onResetKeysChange`
|
|
293
292
|
|
|
294
293
|
This is called when the `resetKeys` are changed (triggering a reset of the
|
|
295
294
|
`ErrorBoundary`). It's called with the `prevResetKeys` and the `resetKeys`.
|
|
296
295
|
|
|
296
|
+
### `useErrorHandler(error?: Error)`
|
|
297
|
+
|
|
298
|
+
React's error boundaries feature is limited in that the boundaries can only
|
|
299
|
+
handle errors thrown during React's lifecycles. To quote
|
|
300
|
+
[the React docs on Error Boundaries](https://reactjs.org/docs/error-boundaries.html):
|
|
301
|
+
|
|
302
|
+
> Error boundaries do not catch errors for:
|
|
303
|
+
>
|
|
304
|
+
> - Event handlers
|
|
305
|
+
> ([learn more](https://reactjs.org/docs/error-boundaries.html#how-about-event-handlers))
|
|
306
|
+
> - Asynchronous code (e.g. setTimeout or requestAnimationFrame callbacks)
|
|
307
|
+
> - Server side rendering
|
|
308
|
+
> - Errors thrown in the error boundary itself (rather than its children)
|
|
309
|
+
|
|
310
|
+
This means you have to handle those errors yourself, but you probably would like
|
|
311
|
+
to reuse the error boundaries you worked hard on creating for those kinds of
|
|
312
|
+
errors as well. This is what `useErrorHandler` is for.
|
|
313
|
+
|
|
314
|
+
There are two ways to use `useErrorHandler`:
|
|
315
|
+
|
|
316
|
+
1. `const handleError = useErrorHandler()`: call `handleError(theError)`
|
|
317
|
+
2. `useErrorHandler(error)`: useful if you are managing the error state yourself
|
|
318
|
+
or get it from another hook.
|
|
319
|
+
|
|
320
|
+
Here's an example:
|
|
321
|
+
|
|
322
|
+
```javascript
|
|
323
|
+
function Greeting() {
|
|
324
|
+
const [greeting, setGreeting] = React.useState(null)
|
|
325
|
+
const handleError = useErrorHandler()
|
|
326
|
+
|
|
327
|
+
function handleSubmit(event) {
|
|
328
|
+
event.preventDefault()
|
|
329
|
+
const name = event.target.elements.name.value
|
|
330
|
+
fetchGreeting(name).then(
|
|
331
|
+
newGreeting => setGreeting(newGreeting),
|
|
332
|
+
handleError,
|
|
333
|
+
)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
return greeting ? (
|
|
337
|
+
<div>{greeting}</div>
|
|
338
|
+
) : (
|
|
339
|
+
<form onSubmit={handleSubmit}>
|
|
340
|
+
<label>Name</label>
|
|
341
|
+
<input id="name" />
|
|
342
|
+
<button type="submit"}>
|
|
343
|
+
get a greeting
|
|
344
|
+
</button>
|
|
345
|
+
</form>
|
|
346
|
+
)
|
|
347
|
+
}
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
> Note, in case it's not clear what's happening here, you could also write
|
|
351
|
+
> `handleSubmit` like this:
|
|
352
|
+
|
|
353
|
+
```javascript
|
|
354
|
+
function handleSubmit(event) {
|
|
355
|
+
event.preventDefault()
|
|
356
|
+
const name = event.target.elements.name.value
|
|
357
|
+
fetchGreeting(name).then(
|
|
358
|
+
newGreeting => setGreeting(newGreeting),
|
|
359
|
+
error => handleError(error),
|
|
360
|
+
)
|
|
361
|
+
}
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
Alternatively, let's say you're using a hook that gives you the error:
|
|
365
|
+
|
|
366
|
+
```javascript
|
|
367
|
+
function Greeting() {
|
|
368
|
+
const [name, setName] = React.useState('')
|
|
369
|
+
const {greeting, error} = useGreeting(name)
|
|
370
|
+
useErrorHandler(error)
|
|
371
|
+
|
|
372
|
+
function handleSubmit(event) {
|
|
373
|
+
event.preventDefault()
|
|
374
|
+
const name = event.target.elements.name.value
|
|
375
|
+
setName(name)
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
return greeting ? (
|
|
379
|
+
<div>{greeting}</div>
|
|
380
|
+
) : (
|
|
381
|
+
<form onSubmit={handleSubmit}>
|
|
382
|
+
<label>Name</label>
|
|
383
|
+
<input id="name" />
|
|
384
|
+
<button type="submit">get a greeting</button>
|
|
385
|
+
</form>
|
|
386
|
+
)
|
|
387
|
+
}
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
In this case, if the `error` is ever set to a truthy value, then it will be
|
|
391
|
+
propagated to the nearest error boundary.
|
|
392
|
+
|
|
393
|
+
In either case, you could handle those errors like this:
|
|
394
|
+
|
|
395
|
+
```javascript
|
|
396
|
+
const ui = (
|
|
397
|
+
<ErrorBoundary FallbackComponent={ErrorFallback}>
|
|
398
|
+
<Greeting />
|
|
399
|
+
</ErrorBoundary>
|
|
400
|
+
)
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
And now that'll handle your runtime errors as well as the async errors in the
|
|
404
|
+
`fetchGreeting` or `useGreeting` code.
|
|
405
|
+
|
|
297
406
|
## Issues
|
|
298
407
|
|
|
299
408
|
_Looking to contribute? Look for the [Good First Issue][good-first-issue]
|
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
var _inheritsLoose = require('@babel/runtime/helpers/inheritsLoose');
|
|
6
|
+
var React = require('react');
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
+
|
|
10
|
+
var _inheritsLoose__default = /*#__PURE__*/_interopDefaultLegacy(_inheritsLoose);
|
|
11
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
9
12
|
|
|
10
13
|
var changedArray = function (a, b) {
|
|
11
14
|
if (a === void 0) {
|
|
@@ -27,7 +30,7 @@ var initialState = {
|
|
|
27
30
|
};
|
|
28
31
|
|
|
29
32
|
var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
30
|
-
|
|
33
|
+
_inheritsLoose__default['default'](ErrorBoundary, _React$Component);
|
|
31
34
|
|
|
32
35
|
function ErrorBoundary() {
|
|
33
36
|
var _this;
|
|
@@ -54,6 +57,12 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
54
57
|
return _this;
|
|
55
58
|
}
|
|
56
59
|
|
|
60
|
+
ErrorBoundary.getDerivedStateFromError = function getDerivedStateFromError(error) {
|
|
61
|
+
return {
|
|
62
|
+
error: error
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
|
|
57
66
|
var _proto = ErrorBoundary.prototype;
|
|
58
67
|
|
|
59
68
|
_proto.componentDidCatch = function componentDidCatch(error, info) {
|
|
@@ -61,16 +70,17 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
61
70
|
|
|
62
71
|
(_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info == null ? void 0 : info.componentStack);
|
|
63
72
|
this.setState({
|
|
64
|
-
error: error,
|
|
65
73
|
info: info
|
|
66
74
|
});
|
|
67
75
|
};
|
|
68
76
|
|
|
69
77
|
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
|
|
70
|
-
var
|
|
78
|
+
var _this$state = this.state,
|
|
79
|
+
error = _this$state.error,
|
|
80
|
+
info = _this$state.info;
|
|
71
81
|
var resetKeys = this.props.resetKeys;
|
|
72
82
|
|
|
73
|
-
if (error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
83
|
+
if (error !== null && info !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
74
84
|
var _this$props$onResetKe, _this$props3;
|
|
75
85
|
|
|
76
86
|
(_this$props$onResetKe = (_this$props3 = this.props).onResetKeysChange) == null ? void 0 : _this$props$onResetKe.call(_this$props3, prevProps.resetKeys, resetKeys);
|
|
@@ -79,27 +89,35 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
79
89
|
};
|
|
80
90
|
|
|
81
91
|
_proto.render = function render() {
|
|
82
|
-
var _this$
|
|
83
|
-
error = _this$
|
|
84
|
-
info = _this$
|
|
92
|
+
var _this$state2 = this.state,
|
|
93
|
+
error = _this$state2.error,
|
|
94
|
+
info = _this$state2.info;
|
|
85
95
|
var _this$props4 = this.props,
|
|
86
96
|
fallbackRender = _this$props4.fallbackRender,
|
|
87
97
|
FallbackComponent = _this$props4.FallbackComponent,
|
|
88
98
|
fallback = _this$props4.fallback;
|
|
89
99
|
|
|
90
100
|
if (error !== null) {
|
|
101
|
+
// we'll get a re-render with the error state in getDerivedStateFromError
|
|
102
|
+
// but we don't have the info yet, so just render null
|
|
103
|
+
// note that this won't be committed to the DOM thanks to our componentDidCatch
|
|
104
|
+
// so the user won't see a flash of nothing, so this works fine.
|
|
105
|
+
// the benefit of doing things this way rather than just putting both the
|
|
106
|
+
// error and info setState within componentDidCatch is we avoid re-rendering
|
|
107
|
+
// busted stuff: https://github.com/bvaughn/react-error-boundary/issues/66
|
|
108
|
+
if (!info) return null;
|
|
91
109
|
var props = {
|
|
92
110
|
componentStack: info == null ? void 0 : info.componentStack,
|
|
93
111
|
error: error,
|
|
94
112
|
resetErrorBoundary: this.resetErrorBoundary
|
|
95
113
|
};
|
|
96
114
|
|
|
97
|
-
if ( /*#__PURE__*/
|
|
115
|
+
if ( /*#__PURE__*/React__default['default'].isValidElement(fallback)) {
|
|
98
116
|
return fallback;
|
|
99
117
|
} else if (typeof fallbackRender === 'function') {
|
|
100
118
|
return fallbackRender(props);
|
|
101
|
-
} else if (
|
|
102
|
-
return /*#__PURE__*/
|
|
119
|
+
} else if (FallbackComponent) {
|
|
120
|
+
return /*#__PURE__*/React__default['default'].createElement(FallbackComponent, props);
|
|
103
121
|
} else {
|
|
104
122
|
throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
|
|
105
123
|
}
|
|
@@ -109,11 +127,11 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
109
127
|
};
|
|
110
128
|
|
|
111
129
|
return ErrorBoundary;
|
|
112
|
-
}(
|
|
130
|
+
}(React__default['default'].Component);
|
|
113
131
|
|
|
114
132
|
function withErrorBoundary(Component, errorBoundaryProps) {
|
|
115
133
|
function Wrapped(props) {
|
|
116
|
-
return /*#__PURE__*/
|
|
134
|
+
return /*#__PURE__*/React__default['default'].createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React__default['default'].createElement(Component, props));
|
|
117
135
|
} // Format for display in DevTools
|
|
118
136
|
|
|
119
137
|
|
|
@@ -122,5 +140,16 @@ function withErrorBoundary(Component, errorBoundaryProps) {
|
|
|
122
140
|
return Wrapped;
|
|
123
141
|
}
|
|
124
142
|
|
|
143
|
+
function useErrorHandler(givenError) {
|
|
144
|
+
var _React$useState = React__default['default'].useState(null),
|
|
145
|
+
error = _React$useState[0],
|
|
146
|
+
setError = _React$useState[1];
|
|
147
|
+
|
|
148
|
+
if (givenError) throw givenError;
|
|
149
|
+
if (error) throw error;
|
|
150
|
+
return setError;
|
|
151
|
+
}
|
|
152
|
+
|
|
125
153
|
exports.ErrorBoundary = ErrorBoundary;
|
|
154
|
+
exports.useErrorHandler = useErrorHandler;
|
|
126
155
|
exports.withErrorBoundary = withErrorBoundary;
|
|
@@ -48,6 +48,12 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
48
48
|
return _this;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
ErrorBoundary.getDerivedStateFromError = function getDerivedStateFromError(error) {
|
|
52
|
+
return {
|
|
53
|
+
error: error
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
|
|
51
57
|
var _proto = ErrorBoundary.prototype;
|
|
52
58
|
|
|
53
59
|
_proto.componentDidCatch = function componentDidCatch(error, info) {
|
|
@@ -55,16 +61,17 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
55
61
|
|
|
56
62
|
(_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info == null ? void 0 : info.componentStack);
|
|
57
63
|
this.setState({
|
|
58
|
-
error: error,
|
|
59
64
|
info: info
|
|
60
65
|
});
|
|
61
66
|
};
|
|
62
67
|
|
|
63
68
|
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
|
|
64
|
-
var
|
|
69
|
+
var _this$state = this.state,
|
|
70
|
+
error = _this$state.error,
|
|
71
|
+
info = _this$state.info;
|
|
65
72
|
var resetKeys = this.props.resetKeys;
|
|
66
73
|
|
|
67
|
-
if (error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
74
|
+
if (error !== null && info !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
68
75
|
var _this$props$onResetKe, _this$props3;
|
|
69
76
|
|
|
70
77
|
(_this$props$onResetKe = (_this$props3 = this.props).onResetKeysChange) == null ? void 0 : _this$props$onResetKe.call(_this$props3, prevProps.resetKeys, resetKeys);
|
|
@@ -73,15 +80,23 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
73
80
|
};
|
|
74
81
|
|
|
75
82
|
_proto.render = function render() {
|
|
76
|
-
var _this$
|
|
77
|
-
error = _this$
|
|
78
|
-
info = _this$
|
|
83
|
+
var _this$state2 = this.state,
|
|
84
|
+
error = _this$state2.error,
|
|
85
|
+
info = _this$state2.info;
|
|
79
86
|
var _this$props4 = this.props,
|
|
80
87
|
fallbackRender = _this$props4.fallbackRender,
|
|
81
88
|
FallbackComponent = _this$props4.FallbackComponent,
|
|
82
89
|
fallback = _this$props4.fallback;
|
|
83
90
|
|
|
84
91
|
if (error !== null) {
|
|
92
|
+
// we'll get a re-render with the error state in getDerivedStateFromError
|
|
93
|
+
// but we don't have the info yet, so just render null
|
|
94
|
+
// note that this won't be committed to the DOM thanks to our componentDidCatch
|
|
95
|
+
// so the user won't see a flash of nothing, so this works fine.
|
|
96
|
+
// the benefit of doing things this way rather than just putting both the
|
|
97
|
+
// error and info setState within componentDidCatch is we avoid re-rendering
|
|
98
|
+
// busted stuff: https://github.com/bvaughn/react-error-boundary/issues/66
|
|
99
|
+
if (!info) return null;
|
|
85
100
|
var props = {
|
|
86
101
|
componentStack: info == null ? void 0 : info.componentStack,
|
|
87
102
|
error: error,
|
|
@@ -92,7 +107,7 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
|
|
|
92
107
|
return fallback;
|
|
93
108
|
} else if (typeof fallbackRender === 'function') {
|
|
94
109
|
return fallbackRender(props);
|
|
95
|
-
} else if (
|
|
110
|
+
} else if (FallbackComponent) {
|
|
96
111
|
return /*#__PURE__*/React.createElement(FallbackComponent, props);
|
|
97
112
|
} else {
|
|
98
113
|
throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
|
|
@@ -116,4 +131,14 @@ function withErrorBoundary(Component, errorBoundaryProps) {
|
|
|
116
131
|
return Wrapped;
|
|
117
132
|
}
|
|
118
133
|
|
|
119
|
-
|
|
134
|
+
function useErrorHandler(givenError) {
|
|
135
|
+
var _React$useState = React.useState(null),
|
|
136
|
+
error = _React$useState[0],
|
|
137
|
+
setError = _React$useState[1];
|
|
138
|
+
|
|
139
|
+
if (givenError) throw givenError;
|
|
140
|
+
if (error) throw error;
|
|
141
|
+
return setError;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export { ErrorBoundary, useErrorHandler, withErrorBoundary };
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
|
|
4
|
-
(global = global || self, factory(global.ReactErrorBoundary = {}, global.React));
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactErrorBoundary = {}, global.React));
|
|
5
5
|
}(this, (function (exports, React) { 'use strict';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
8
10
|
|
|
9
11
|
function _inheritsLoose(subClass, superClass) {
|
|
10
12
|
subClass.prototype = Object.create(superClass.prototype);
|
|
@@ -59,6 +61,12 @@
|
|
|
59
61
|
return _this;
|
|
60
62
|
}
|
|
61
63
|
|
|
64
|
+
ErrorBoundary.getDerivedStateFromError = function getDerivedStateFromError(error) {
|
|
65
|
+
return {
|
|
66
|
+
error: error
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
62
70
|
var _proto = ErrorBoundary.prototype;
|
|
63
71
|
|
|
64
72
|
_proto.componentDidCatch = function componentDidCatch(error, info) {
|
|
@@ -66,16 +74,17 @@
|
|
|
66
74
|
|
|
67
75
|
(_this$props$onError = (_this$props2 = this.props).onError) == null ? void 0 : _this$props$onError.call(_this$props2, error, info == null ? void 0 : info.componentStack);
|
|
68
76
|
this.setState({
|
|
69
|
-
error: error,
|
|
70
77
|
info: info
|
|
71
78
|
});
|
|
72
79
|
};
|
|
73
80
|
|
|
74
81
|
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
|
|
75
|
-
var
|
|
82
|
+
var _this$state = this.state,
|
|
83
|
+
error = _this$state.error,
|
|
84
|
+
info = _this$state.info;
|
|
76
85
|
var resetKeys = this.props.resetKeys;
|
|
77
86
|
|
|
78
|
-
if (error !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
87
|
+
if (error !== null && info !== null && changedArray(prevProps.resetKeys, resetKeys)) {
|
|
79
88
|
var _this$props$onResetKe, _this$props3;
|
|
80
89
|
|
|
81
90
|
(_this$props$onResetKe = (_this$props3 = this.props).onResetKeysChange) == null ? void 0 : _this$props$onResetKe.call(_this$props3, prevProps.resetKeys, resetKeys);
|
|
@@ -84,27 +93,35 @@
|
|
|
84
93
|
};
|
|
85
94
|
|
|
86
95
|
_proto.render = function render() {
|
|
87
|
-
var _this$
|
|
88
|
-
error = _this$
|
|
89
|
-
info = _this$
|
|
96
|
+
var _this$state2 = this.state,
|
|
97
|
+
error = _this$state2.error,
|
|
98
|
+
info = _this$state2.info;
|
|
90
99
|
var _this$props4 = this.props,
|
|
91
100
|
fallbackRender = _this$props4.fallbackRender,
|
|
92
101
|
FallbackComponent = _this$props4.FallbackComponent,
|
|
93
102
|
fallback = _this$props4.fallback;
|
|
94
103
|
|
|
95
104
|
if (error !== null) {
|
|
105
|
+
// we'll get a re-render with the error state in getDerivedStateFromError
|
|
106
|
+
// but we don't have the info yet, so just render null
|
|
107
|
+
// note that this won't be committed to the DOM thanks to our componentDidCatch
|
|
108
|
+
// so the user won't see a flash of nothing, so this works fine.
|
|
109
|
+
// the benefit of doing things this way rather than just putting both the
|
|
110
|
+
// error and info setState within componentDidCatch is we avoid re-rendering
|
|
111
|
+
// busted stuff: https://github.com/bvaughn/react-error-boundary/issues/66
|
|
112
|
+
if (!info) return null;
|
|
96
113
|
var props = {
|
|
97
114
|
componentStack: info == null ? void 0 : info.componentStack,
|
|
98
115
|
error: error,
|
|
99
116
|
resetErrorBoundary: this.resetErrorBoundary
|
|
100
117
|
};
|
|
101
118
|
|
|
102
|
-
if ( /*#__PURE__*/
|
|
119
|
+
if ( /*#__PURE__*/React__default['default'].isValidElement(fallback)) {
|
|
103
120
|
return fallback;
|
|
104
121
|
} else if (typeof fallbackRender === 'function') {
|
|
105
122
|
return fallbackRender(props);
|
|
106
|
-
} else if (
|
|
107
|
-
return /*#__PURE__*/
|
|
123
|
+
} else if (FallbackComponent) {
|
|
124
|
+
return /*#__PURE__*/React__default['default'].createElement(FallbackComponent, props);
|
|
108
125
|
} else {
|
|
109
126
|
throw new Error('react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop');
|
|
110
127
|
}
|
|
@@ -114,11 +131,11 @@
|
|
|
114
131
|
};
|
|
115
132
|
|
|
116
133
|
return ErrorBoundary;
|
|
117
|
-
}(
|
|
134
|
+
}(React__default['default'].Component);
|
|
118
135
|
|
|
119
136
|
function withErrorBoundary(Component, errorBoundaryProps) {
|
|
120
137
|
function Wrapped(props) {
|
|
121
|
-
return /*#__PURE__*/
|
|
138
|
+
return /*#__PURE__*/React__default['default'].createElement(ErrorBoundary, errorBoundaryProps, /*#__PURE__*/React__default['default'].createElement(Component, props));
|
|
122
139
|
} // Format for display in DevTools
|
|
123
140
|
|
|
124
141
|
|
|
@@ -127,7 +144,18 @@
|
|
|
127
144
|
return Wrapped;
|
|
128
145
|
}
|
|
129
146
|
|
|
147
|
+
function useErrorHandler(givenError) {
|
|
148
|
+
var _React$useState = React__default['default'].useState(null),
|
|
149
|
+
error = _React$useState[0],
|
|
150
|
+
setError = _React$useState[1];
|
|
151
|
+
|
|
152
|
+
if (givenError) throw givenError;
|
|
153
|
+
if (error) throw error;
|
|
154
|
+
return setError;
|
|
155
|
+
}
|
|
156
|
+
|
|
130
157
|
exports.ErrorBoundary = ErrorBoundary;
|
|
158
|
+
exports.useErrorHandler = useErrorHandler;
|
|
131
159
|
exports.withErrorBoundary = withErrorBoundary;
|
|
132
160
|
|
|
133
161
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-error-boundary.umd.js","sources":["../node_modules/@babel/runtime/helpers/esm/inheritsLoose.js","../src/index.js"],"sourcesContent":["export default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}","import React from 'react'\n\nconst changedArray = (a = [], b = []) =>\n a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]))\n\nconst initialState = {error: null, info: null}\nclass ErrorBoundary extends React.Component {\n state = initialState\n resetErrorBoundary = (...args) => {\n this.props.onReset?.(...args)\n this.setState(initialState)\n }\n\n componentDidCatch(error, info) {\n this.props.onError?.(error, info?.componentStack)\n this.setState({
|
|
1
|
+
{"version":3,"file":"react-error-boundary.umd.js","sources":["../node_modules/@babel/runtime/helpers/esm/inheritsLoose.js","../src/index.js"],"sourcesContent":["export default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}","import React from 'react'\n\nconst changedArray = (a = [], b = []) =>\n a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]))\n\nconst initialState = {error: null, info: null}\nclass ErrorBoundary extends React.Component {\n static getDerivedStateFromError(error) {\n return {error}\n }\n\n state = initialState\n resetErrorBoundary = (...args) => {\n this.props.onReset?.(...args)\n this.setState(initialState)\n }\n\n componentDidCatch(error, info) {\n this.props.onError?.(error, info?.componentStack)\n this.setState({info})\n }\n\n componentDidUpdate(prevProps) {\n const {error, info} = this.state\n const {resetKeys} = this.props\n if (\n error !== null &&\n info !== null &&\n changedArray(prevProps.resetKeys, resetKeys)\n ) {\n this.props.onResetKeysChange?.(prevProps.resetKeys, resetKeys)\n this.setState(initialState)\n }\n }\n\n render() {\n const {error, info} = this.state\n const {fallbackRender, FallbackComponent, fallback} = this.props\n\n if (error !== null) {\n // we'll get a re-render with the error state in getDerivedStateFromError\n // but we don't have the info yet, so just render null\n // note that this won't be committed to the DOM thanks to our componentDidCatch\n // so the user won't see a flash of nothing, so this works fine.\n // the benefit of doing things this way rather than just putting both the\n // error and info setState within componentDidCatch is we avoid re-rendering\n // busted stuff: https://github.com/bvaughn/react-error-boundary/issues/66\n if (!info) return null\n\n const props = {\n componentStack: info?.componentStack,\n error,\n resetErrorBoundary: this.resetErrorBoundary,\n }\n if (React.isValidElement(fallback)) {\n return fallback\n } else if (typeof fallbackRender === 'function') {\n return fallbackRender(props)\n } else if (FallbackComponent) {\n return <FallbackComponent {...props} />\n } else {\n throw new Error(\n 'react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop',\n )\n }\n }\n\n return this.props.children\n }\n}\n\nfunction withErrorBoundary(Component, errorBoundaryProps) {\n function Wrapped(props) {\n return (\n <ErrorBoundary {...errorBoundaryProps}>\n <Component {...props} />\n </ErrorBoundary>\n )\n }\n\n // Format for display in DevTools\n const name = Component.displayName || Component.name || 'Unknown'\n Wrapped.displayName = `withErrorBoundary(${name})`\n\n return Wrapped\n}\n\nfunction useErrorHandler(givenError) {\n const [error, setError] = React.useState(null)\n if (givenError) throw givenError\n if (error) throw error\n return setError\n}\n\nexport {ErrorBoundary, withErrorBoundary, useErrorHandler}\n"],"names":["_inheritsLoose","subClass","superClass","prototype","Object","create","constructor","__proto__","changedArray","a","b","length","some","item","index","is","initialState","error","info","ErrorBoundary","state","resetErrorBoundary","args","props","onReset","setState","getDerivedStateFromError","componentDidCatch","onError","componentStack","componentDidUpdate","prevProps","resetKeys","onResetKeysChange","render","fallbackRender","FallbackComponent","fallback","React","isValidElement","Error","children","Component","withErrorBoundary","errorBoundaryProps","Wrapped","name","displayName","useErrorHandler","givenError","useState","setError"],"mappings":"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"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],r):r((e=e||self).ReactErrorBoundary={},e.React)}(this,(function(e,r){"use strict";
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).ReactErrorBoundary={},e.React)}(this,(function(e,r){"use strict";function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=t(r);var o={error:null,info:null},a=function(e){var r,t;function a(){for(var r,t=arguments.length,n=new Array(t),a=0;a<t;a++)n[a]=arguments[a];return(r=e.call.apply(e,[this].concat(n))||this).state=o,r.resetErrorBoundary=function(){for(var e,t=arguments.length,n=new Array(t),a=0;a<t;a++)n[a]=arguments[a];null==r.props.onReset||(e=r.props).onReset.apply(e,n),r.setState(o)},r}t=e,(r=a).prototype=Object.create(t.prototype),r.prototype.constructor=r,r.__proto__=t,a.getDerivedStateFromError=function(e){return{error:e}};var l=a.prototype;return l.componentDidCatch=function(e,r){var t,n;null==(t=(n=this.props).onError)||t.call(n,e,null==r?void 0:r.componentStack),this.setState({info:r})},l.componentDidUpdate=function(e){var r,t,n,a,l=this.state,i=l.error,u=l.info,s=this.props.resetKeys;null!==i&&null!==u&&(void 0===(n=e.resetKeys)&&(n=[]),void 0===(a=s)&&(a=[]),n.length!==a.length||n.some((function(e,r){return!Object.is(e,a[r])})))&&(null==(r=(t=this.props).onResetKeysChange)||r.call(t,e.resetKeys,s),this.setState(o))},l.render=function(){var e=this.state,r=e.error,t=e.info,o=this.props,a=o.fallbackRender,l=o.FallbackComponent,i=o.fallback;if(null!==r){if(!t)return null;var u={componentStack:null==t?void 0:t.componentStack,error:r,resetErrorBoundary:this.resetErrorBoundary};if(n.default.isValidElement(i))return i;if("function"==typeof a)return a(u);if(l)return n.default.createElement(l,u);throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop")}return this.props.children},a}(n.default.Component);e.ErrorBoundary=a,e.useErrorHandler=function(e){var r=n.default.useState(null),t=r[0],o=r[1];if(e)throw e;if(t)throw t;return o},e.withErrorBoundary=function(e,r){function t(t){return n.default.createElement(a,r,n.default.createElement(e,t))}var o=e.displayName||e.name||"Unknown";return t.displayName="withErrorBoundary("+o+")",t},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=react-error-boundary.umd.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-error-boundary.umd.min.js","sources":["../src/index.js","../node_modules/@babel/runtime/helpers/esm/inheritsLoose.js"],"sourcesContent":["import React from 'react'\n\nconst changedArray = (a = [], b = []) =>\n a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]))\n\nconst initialState = {error: null, info: null}\nclass ErrorBoundary extends React.Component {\n state = initialState\n resetErrorBoundary = (...args) => {\n this.props.onReset?.(...args)\n this.setState(initialState)\n }\n\n componentDidCatch(error, info) {\n this.props.onError?.(error, info?.componentStack)\n this.setState({
|
|
1
|
+
{"version":3,"file":"react-error-boundary.umd.min.js","sources":["../src/index.js","../node_modules/@babel/runtime/helpers/esm/inheritsLoose.js"],"sourcesContent":["import React from 'react'\n\nconst changedArray = (a = [], b = []) =>\n a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]))\n\nconst initialState = {error: null, info: null}\nclass ErrorBoundary extends React.Component {\n static getDerivedStateFromError(error) {\n return {error}\n }\n\n state = initialState\n resetErrorBoundary = (...args) => {\n this.props.onReset?.(...args)\n this.setState(initialState)\n }\n\n componentDidCatch(error, info) {\n this.props.onError?.(error, info?.componentStack)\n this.setState({info})\n }\n\n componentDidUpdate(prevProps) {\n const {error, info} = this.state\n const {resetKeys} = this.props\n if (\n error !== null &&\n info !== null &&\n changedArray(prevProps.resetKeys, resetKeys)\n ) {\n this.props.onResetKeysChange?.(prevProps.resetKeys, resetKeys)\n this.setState(initialState)\n }\n }\n\n render() {\n const {error, info} = this.state\n const {fallbackRender, FallbackComponent, fallback} = this.props\n\n if (error !== null) {\n // we'll get a re-render with the error state in getDerivedStateFromError\n // but we don't have the info yet, so just render null\n // note that this won't be committed to the DOM thanks to our componentDidCatch\n // so the user won't see a flash of nothing, so this works fine.\n // the benefit of doing things this way rather than just putting both the\n // error and info setState within componentDidCatch is we avoid re-rendering\n // busted stuff: https://github.com/bvaughn/react-error-boundary/issues/66\n if (!info) return null\n\n const props = {\n componentStack: info?.componentStack,\n error,\n resetErrorBoundary: this.resetErrorBoundary,\n }\n if (React.isValidElement(fallback)) {\n return fallback\n } else if (typeof fallbackRender === 'function') {\n return fallbackRender(props)\n } else if (FallbackComponent) {\n return <FallbackComponent {...props} />\n } else {\n throw new Error(\n 'react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop',\n )\n }\n }\n\n return this.props.children\n }\n}\n\nfunction withErrorBoundary(Component, errorBoundaryProps) {\n function Wrapped(props) {\n return (\n <ErrorBoundary {...errorBoundaryProps}>\n <Component {...props} />\n </ErrorBoundary>\n )\n }\n\n // Format for display in DevTools\n const name = Component.displayName || Component.name || 'Unknown'\n Wrapped.displayName = `withErrorBoundary(${name})`\n\n return Wrapped\n}\n\nfunction useErrorHandler(givenError) {\n const [error, setError] = React.useState(null)\n if (givenError) throw givenError\n if (error) throw error\n return setError\n}\n\nexport {ErrorBoundary, withErrorBoundary, useErrorHandler}\n","export default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}"],"names":["initialState","error","info","ErrorBoundary","subClass","superClass","state","resetErrorBoundary","args","props","onReset","setState","prototype","Object","create","constructor","__proto__","getDerivedStateFromError","componentDidCatch","onError","componentStack","componentDidUpdate","prevProps","a","b","this","resetKeys","length","some","item","index","is","onResetKeysChange","render","fallbackRender","FallbackComponent","fallback","React","isValidElement","Error","children","Component","givenError","useState","setError","errorBoundaryProps","Wrapped","name","displayName"],"mappings":"gXAEA,IAGMA,EAAe,CAACC,MAAO,KAAMC,KAAM,MACnCC,cCNS,IAAwBC,EAAUC,0IDW/CC,MAAQN,IACRO,mBAAqB,wCAAIC,2BAAAA,0BAClBC,MAAMC,cAAND,OAAMC,gBAAaF,KACnBG,SAASX,MCd+BK,KAAVD,KAC5BQ,UAAYC,OAAOC,OAAOT,EAAWO,WAC9CR,EAASQ,UAAUG,YAAcX,EACjCA,EAASY,UAAYX,IDIdY,yBAAP,SAAgChB,SACvB,CAACA,MAAAA,+BASViB,kBAAA,SAAkBjB,EAAOC,4BAClBO,OAAMU,mBAAUlB,QAAOC,SAAAA,EAAMkB,qBAC7BT,SAAS,CAACT,KAAAA,OAGjBmB,mBAAA,SAAmBC,WApBCC,EAAQC,IAqBJC,KAAKnB,MAApBL,IAAAA,MAAOC,IAAAA,KACPwB,EAAaD,KAAKhB,MAAlBiB,UAEK,OAAVzB,GACS,OAATC,cAzBgBqB,EA0BHD,EAAUI,aA1BPH,EAAI,cAAIC,EA0BUE,KA1BVF,EAAI,IAChCD,EAAEI,SAAWH,EAAEG,QAAUJ,EAAEK,MAAK,SAACC,EAAMC,UAAWjB,OAAOkB,GAAGF,EAAML,EAAEM,2BA2B3DrB,OAAMuB,6BAAoBV,EAAUI,UAAWA,QAC/Cf,SAASX,OAIlBiC,OAAA,iBACwBR,KAAKnB,MAApBL,IAAAA,MAAOC,IAAAA,OACwCuB,KAAKhB,MAApDyB,IAAAA,eAAgBC,IAAAA,kBAAmBC,IAAAA,YAE5B,OAAVnC,EAAgB,KAQbC,EAAM,OAAO,SAEZO,EAAQ,CACZW,qBAAgBlB,SAAAA,EAAMkB,eACtBnB,MAAAA,EACAM,mBAAoBkB,KAAKlB,uBAEvB8B,UAAMC,eAAeF,UAChBA,EACF,GAA8B,mBAAnBF,SACTA,EAAezB,GACjB,GAAI0B,SACFE,wBAACF,EAAsB1B,SAExB,IAAI8B,MACR,qGAKCd,KAAKhB,MAAM+B,aA7DMH,UAAMI,+CAiFlC,SAAyBC,SACGL,UAAMM,SAAS,MAAlC1C,OAAO2C,UACVF,EAAY,MAAMA,KAClBzC,EAAO,MAAMA,SACV2C,uBApBT,SAA2BH,EAAWI,YAC3BC,EAAQrC,UAEb4B,wBAAClC,EAAkB0C,EACjBR,wBAACI,EAAchC,QAMfsC,EAAON,EAAUO,aAAeP,EAAUM,MAAQ,iBACxDD,EAAQE,iCAAmCD,MAEpCD"}
|
package/index.d.ts
CHANGED
|
@@ -41,3 +41,7 @@ export function withErrorBoundary<P>(
|
|
|
41
41
|
ComponentToDecorate: React.ComponentType<P>,
|
|
42
42
|
errorBoundaryProps: ErrorBoundaryProps,
|
|
43
43
|
): React.ComponentType<P>
|
|
44
|
+
|
|
45
|
+
export function useErrorHandler<P = Error>(
|
|
46
|
+
error?: P,
|
|
47
|
+
): React.Dispatch<React.SetStateAction<P>>
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-error-boundary",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"description": "Simple reusable React error boundary component",
|
|
5
5
|
"main": "dist/react-error-boundary.cjs.js",
|
|
6
6
|
"module": "dist/react-error-boundary.esm.js",
|
|
7
7
|
"browser": "dist/react-error-boundary.umd.js",
|
|
8
|
+
"types": "index.d.ts",
|
|
8
9
|
"sideEffects": false,
|
|
9
10
|
"keywords": [
|
|
10
11
|
"react",
|
|
@@ -38,25 +39,26 @@
|
|
|
38
39
|
"validate": "kcd-scripts validate"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"@babel/runtime": "^7.
|
|
42
|
+
"@babel/runtime": "^7.11.2"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
|
-
"@testing-library/jest-dom": "^5.
|
|
45
|
-
"@testing-library/react": "^
|
|
46
|
-
"@testing-library/user-event": "^
|
|
47
|
-
"kcd-scripts": "^
|
|
45
|
+
"@testing-library/jest-dom": "^5.11.4",
|
|
46
|
+
"@testing-library/react": "^11.0.2",
|
|
47
|
+
"@testing-library/user-event": "^12.1.4",
|
|
48
|
+
"kcd-scripts": "^6.3.0",
|
|
48
49
|
"react": "^16.13.1",
|
|
49
50
|
"react-dom": "^16.13.1",
|
|
50
|
-
"typescript": "^
|
|
51
|
+
"typescript": "^4.0.2"
|
|
51
52
|
},
|
|
52
53
|
"peerDependencies": {
|
|
53
|
-
"react": ">=16.
|
|
54
|
+
"react": ">=16.13.1"
|
|
54
55
|
},
|
|
55
56
|
"eslintConfig": {
|
|
56
57
|
"extends": "./node_modules/kcd-scripts/eslint.js",
|
|
57
58
|
"rules": {
|
|
58
59
|
"react/prop-types": "off",
|
|
59
|
-
"react/no-did-update-set-state": "off"
|
|
60
|
+
"react/no-did-update-set-state": "off",
|
|
61
|
+
"babel/no-unused-expressions": "off"
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
64
|
}
|