score:2

Accepted answer
let count = '0';

count = count + 1;

console.log('count = ', count);

score:0

resetCount: function() {  
    this.setState({  
        count: 0
    })
},

addOne: function() { 
    this.setState({
        count: this.state.count + 1
    })
},

getInitialState: function() { 
    return {
        count: 0
    }
},

score:0

count: 0

score:0

var CountComponent = React.createClass({

    resetCount: function() {  
        this.setState({  
            count: 0
        })
    },

    addOne: function() { 
        this.setState({
            count: this.state.count + 1
        })
    },

    getInitialState: function() { 
        return {
            count: 0
        }
    },

    render: function() {
        return (
            <div>
                <h1>Count {this.state.count}</h1>
                <button onClick={this.addOne}>Add 1</button>
                <button onClick={this.resetCount}>Reset</button>
            </div>
        )
    }
});

React.render(
    <CountComponent />,
    document.getElementById('app') 
);

score:4

   addOne: function() { 
        this.setState({
            count: +this.state.count + 1
        })
    },

Related Query

More Query from same tag