diff --git a/src/components/CodeEditor/CodeEditor.js b/src/components/CodeEditor/CodeEditor.js index cfe881355df..837458a670c 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,11 @@ class CodeEditor extends Component { } render() { - const {children, code} = this.props; - const {error} = this.state; + const {children} = this.props; + const {compiledES6, code, error, showJSX} = this.state; return ( - +
- Live JSX Editor + + Live JSX Editor + +
{ - this.setState(this._updateState(code)); + this.setState(state => this._updateState(code, state.showJSX)); }; }