简单教程
提交运行
代码编辑器:
<title>React Hello World -简单教程 </title> <script src="https://cdn.staticfile.org/react/15.5.4/react.min.js"></script> <script src="https://cdn.staticfile.org/react/15.5.4/react-dom.min.js"></script> <script src="https://cdn.staticfile.org/babel-standalone/6.24.0/babel.min.js"></script> <div id="app"></div> <script type="text/babel"> var Content = React.createClass({ render: function() { return <div> <button onClick = {this.props.updateStateProp}>点我</button> <h4>{this.props.myDataProp}</h4> </div> } }); var HelloMessage = React.createClass({ getInitialState: function() { return {value: 'Hello 简单编程!'}; }, handleChange: function(event) { this.setState({value: '简单编程'}) }, render: function() { var value = this.state.value; return <div> <Content myDataProp = {value} updateStateProp = {this.handleChange}></Content> </div>; } }); ReactDOM.render( <HelloMessage />, document.getElementById('app') ); </script>
运行结果: