我正在使用 codemirror 创建一个组件,但似乎我的代码中的某些内容是错误的,因为当我尝试更新我的主要组件的状态时,应用程序会破坏浏览器,我的研究指向一个无限循环,至少我可以看到当我正在尝试调试。
我希望你们中有人能帮助我解决这个问题,也许是我的错,谢谢。
import React, { Component, PropTypes } from 'react';
import Editor from '../editor';
import Preview from '../preview';
class Playground extends Component {
constructor(props) {
super(props);
this.state = {
code: 'Hi I am a component',
newCode: ''
};
this.handleCodeChange = this.handleCodeChange.bind(this);
}
handleCodeChange(code) {
// Everything works fine until this step, when the component wants to update the state, start the infinite loop
this.setState({ newCode: code });
}
loadCode(code) {
this.refs.editor.setCode(code);
}
render() {
return (
<div> …Run Code Online (Sandbox Code Playgroud)