Ad

Event Not Binding Using React JS

- 1 answer

Not able to bind event properly , & not even getting console errors for the same. As i am new to react, so not able to figure it out.

var Products = React.createClass({
        getInitialState: function() {
            return {
                time: 0
            };
        },

        onClick: function(e) {
            this.setState({
                time: e.target.value /* or any value*/
            });
        },

        render: function() {
            return <div onclick={this.onClick} > Getting used to it {
                this.state.time
            } < /div>
    }

   });

   React.render( <Products /> , document.getElementById('myDiv'))
Ad

Answer

onclick attributes in React are camelcased

return <div onClick={this.onClick} >

Ad
source: stackoverflow.com
Ad