diff --git a/src/components/CodeEditor/CodeEditor.js b/src/components/CodeEditor/CodeEditor.js index 9fb5fc94..8f9a3de4 100644 --- a/src/components/CodeEditor/CodeEditor.js +++ b/src/components/CodeEditor/CodeEditor.js @@ -11,18 +11,23 @@ import ReactDOM from 'react-dom'; import Remarkable from 'remarkable'; // TODO: switch back to the upstream version of react-live // once https://github.com/FormidableLabs/react-live/issues/37 is fixed. -import {LiveProvider, LiveEditor} from '@gaearon/react-live'; +import {LiveEditor, LiveProvider} from '@gaearon/react-live'; import {colors, media} from 'theme'; import MetaTitle from 'templates/components/MetaTitle'; -const compile = code => - Babel.transform(code, {presets: ['es2015', 'react']}).code; // eslint-disable-line no-undef +const compileES5 = ( + code, // eslint-disable-next-line no-undef +) => Babel.transform(code, {presets: ['es2015', 'react']}).code; + +// eslint-disable-next-line no-undef +const compileES6 = code => Babel.transform(code, {presets: ['react']}).code; class CodeEditor extends Component { constructor(props, context) { super(props, context); this.state = this._updateState(props.code); + this.state.showJSX = true; } componentDidMount() { @@ -38,11 +43,17 @@ class CodeEditor extends Component { } render() { - const {children, code} = this.props; - const {error} = this.state; + const {children} = this.props; + const { + compiledES6, + code, + error, + showBabelErrorMessage, + showJSX, + } = this.state; let errorMessage; - if (this.state.showBabelErrorMessage) { + if (showBabelErrorMessage) { errorMessage = ( Babel could not be loaded. @@ -58,7 +69,7 @@ class CodeEditor extends Component { } return ( - +
- Live JSX Editor + + Live JSX Editor + +
{ - this.setState(this._updateState(code)); + this.setState(state => this._updateState(code, state.showJSX)); }; }