http://codepen.io/JessieZhou/pen/VPgMdP,这里有一个在 CodePen 中使用 React 的演示,但是浏览器报错“Uncaught ReferenceError: Component is not defined”。但是,如果我在第一行插入一行“import {Component} from 'react'”,错误将是“Uncaught ReferenceError: require is not defined”。'class'的使用是否有可能导致这个问题?
这是我的代码:
//import {Component} from 'react'
class MyInput extends Component{
constructor(props){
super(props);
this.handleChange = this.handleChange.bind(this);
}
handleChange(e){
this.props.update(e.target.value);
}
render(){
return <input onChange={this.handleChange} type="text"/>
}
}
ReactDOM.render(MyInput, document.getElementById('myinput'));
这是我在 CodePen 中的 javascript 设置:codepen 中的 javascript 设置