Skip to content

Commit e2420ff

Browse files
committed
Added boundaries to CodeEditor and layout component
1 parent 695e790 commit e2420ff

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

src/components/CodeEditor/CodeEditor.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Remarkable from 'remarkable';
1717
import {LiveProvider, LiveEditor} from '@gaearon/react-live';
1818
import {colors, media} from 'theme';
1919
import MetaTitle from 'templates/components/MetaTitle';
20+
import ErrorBoundary from '../ErrorBoundary';
2021

2122
const compile = code =>
2223
Babel.transform(code, {presets: ['es2015', 'react']}).code; // eslint-disable-line no-undef
@@ -285,4 +286,4 @@ class CodeEditor extends Component {
285286
};
286287
}
287288

288-
export default CodeEditor;
289+
export default ErrorBoundary(CodeEditor);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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;

src/components/ErrorBoundary/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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;

src/layouts/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import '../prism-styles';
2525
import 'glamor/reset';
2626
import 'css/reset.css';
2727
import 'css/algolia.css';
28+
import ErrorBoundary from '../components/ErrorBoundary';
2829

2930
class Template extends Component {
3031
componentDidMount() {
@@ -82,4 +83,4 @@ class Template extends Component {
8283
}
8384
}
8485

85-
export default Template;
86+
export default ErrorBoundary(Template);

0 commit comments

Comments
 (0)