File tree Expand file tree Collapse file tree 3 files changed +26
-24
lines changed Expand file tree Collapse file tree 3 files changed +26
-24
lines changed Original file line number Diff line number Diff line change 17
17
18
18
# Editor
19
19
/.idea /
20
+
21
+ # React
22
+ ! /src /react /* .js
Original file line number Diff line number Diff line change 3
3
* As soon as React provides a mechanism for error-catching using functional component,
4
4
* this is likely to be deprecated and/or move to user space.
5
5
" )
6
- type reactComponentClass
7
-
8
- @module ("react" ) external component : reactComponentClass = "Component"
9
-
10
6
type info = {componentStack : string }
11
7
12
8
type params <'error > = {
13
9
error : 'error ,
14
10
info : info ,
15
11
}
16
12
17
- let getErrorBoundary : reactComponentClass => React .element = %raw (`
18
- function (Component ) {
19
- function ErrorBoundary (props ) {
20
- Component .call (this );
21
- this .state = {error: undefined };
22
- };
23
- ErrorBoundary .prototype = Object .create (Component .prototype );
24
- ErrorBoundary .prototype .componentDidCatch = function (error , info ) {
25
- this .setState ({error: {error: error, info: info}})
26
- };
27
- ErrorBoundary .prototype .render = function () {
28
- return this .state .error != undefined ? this .props .fallback (this .state .error ) : this .props .children
29
- }
30
- return ErrorBoundary;
31
- }
32
- ` )
33
-
34
- @react.component
35
- let make = (~children as _ : React .element , ~fallback as _ : params <'error > => React .element ) =>
36
- getErrorBoundary (component )
13
+ @react.component @module ("./react/ErrorBoundary.js" )
14
+ external make : (
15
+ ~children : React .element ,
16
+ ~fallback : params <'error > => React .element ,
17
+ ) => React .element = "default"
Original file line number Diff line number Diff line change
1
+ var React = require ( "react" ) ;
2
+
3
+ export default ( function ( Component ) {
4
+ function ErrorBoundary ( props ) {
5
+ Component . call ( this ) ;
6
+ this . state = { error : undefined } ;
7
+ }
8
+ ErrorBoundary . prototype = Object . create ( Component . prototype ) ;
9
+ ErrorBoundary . prototype . componentDidCatch = function ( error , info ) {
10
+ this . setState ( { error : { error : error , info : info } } ) ;
11
+ } ;
12
+ ErrorBoundary . prototype . render = function ( ) {
13
+ return this . state . error != undefined
14
+ ? this . props . fallback ( this . state . error )
15
+ : this . props . children ;
16
+ } ;
17
+ return ErrorBoundary ;
18
+ } ) ( React . Component ) ;
You can’t perform that action at this time.
0 commit comments