javascript - In Reactjs, how to send and respond to user defined event? -
in reactjs, how send user defined event? , response user defined event? can please give example? e.g. user.newitemaddtocart
below code example responding standard dom event.
var addfriend = react.createclass({ getinitialstate: function(){ return { newfriend: '' } }, updatenewfriend: function(e){ this.setstate({ newfriend: e.target.value }); }, handleaddnew: function(){ this.props.addnew(this.state.newfriend); this.setstate({ newfriend: '' }); }, render: function(){ return ( <div> <input type="text" value={this.state.newfriend} onchange={this.updatenewfriend} /> <button onclick={this.handleaddnew}> add friend </button> <span onuser.newitemaddtocart= {...}> work?</span> </div> ); } });
Comments
Post a Comment