简单教程
提交运行
代码编辑器:
<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 Counter = React.createClass({ getInitialState: function () { return { clickCount: 0 }; }, handleClick: function () { this.setState(function(state) { return {clickCount: state.clickCount + 1}; }); }, render: function () { return (<h2 onClick={this.handleClick}>点我!点击次数为: {this.state.clickCount}</h2>); } }); ReactDOM.render( <Counter />, document.getElementById('app') ); </script>
运行结果: