react官方tutorial心得

"use strict";
var React = require('react');
var ReactDOM = require('react-dom');

class Counter extends React.Component {
    constructor(props) {
        super(props);
        this.state = {count: 0};
    }

    tick() {
        this.setState({count: this.state.count + 1});
    }

    render() {
        return (
            <div className="text-center">
                <h1>
                    Clicks: {this.state.count}
                </h1>
                <button className="btn btn-info" onClick={this.tick.bind(this)}>加1</button>
            </div>


        )
    }
}


ReactDOM.render(<Counter />, document.getElementById('app'))

    原文作者:Prasanta
    原文地址: https://segmentfault.com/a/1190000004307104
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞