File tree 4 files changed +57
-2
lines changed
4 files changed +57
-2
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import Remarkable from 'remarkable';
17
17
import { LiveProvider , LiveEditor } from '@gaearon/react-live' ;
18
18
import { colors , media } from 'theme' ;
19
19
import MetaTitle from 'templates/components/MetaTitle' ;
20
+ import ErrorBoundary from '../ErrorBoundary' ;
20
21
21
22
const compile = code =>
22
23
Babel . transform ( code , { presets : [ 'es2015' , 'react' ] } ) . code ; // eslint-disable-line no-undef
@@ -285,4 +286,4 @@ class CodeEditor extends Component {
285
286
} ;
286
287
}
287
288
288
- export default CodeEditor ;
289
+ export default ErrorBoundary ( CodeEditor ) ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright (c) 2013-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @emails react-core
8
+ */
9
+
10
+ 'use strict' ;
11
+
12
+ import React , { Component } from 'react' ;
13
+
14
+ function ErrorBoundary ( WrappedComponent ) {
15
+ return class extends Component {
16
+ constructor ( props , context ) {
17
+ super ( props , context ) ;
18
+
19
+ this . state = {
20
+ error : null ,
21
+ } ;
22
+ }
23
+
24
+ componentDidCatch ( error ) {
25
+ this . setState ( { error } ) ;
26
+ }
27
+
28
+ render ( ) {
29
+ console . log ( this . state ) ;
30
+ if ( this . state . error ) {
31
+ alert ( 'Error, try to whitelist the site in AdBlocker/Cookie Whitelist' ) ;
32
+ return ;
33
+ }
34
+ return < WrappedComponent { ...this . props } /> ;
35
+ }
36
+ }
37
+ }
38
+
39
+ export default ErrorBoundary ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright (c) 2013-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @emails react-core
8
+ */
9
+
10
+ 'use strict' ;
11
+
12
+ import ErrorBoundary from './ErrorBoundary' ;
13
+
14
+ export default ErrorBoundary ;
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import '../prism-styles';
25
25
import 'glamor/reset' ;
26
26
import 'css/reset.css' ;
27
27
import 'css/algolia.css' ;
28
+ import ErrorBoundary from '../components/ErrorBoundary' ;
28
29
29
30
class Template extends Component {
30
31
componentDidMount ( ) {
@@ -82,4 +83,4 @@ class Template extends Component {
82
83
}
83
84
}
84
85
85
- export default Template ;
86
+ export default ErrorBoundary ( Template ) ;
You can’t perform that action at this time.
0 commit comments