javascript - Passing props to parent in React JS -


here have text field default number "3", , want updated when input value , click button. since, i'm updating value in child, don't know how pass props parent.

var game = react.createclass({     getinitialstate: function() {         return {            input: 3         };     },      setsize: function() {         //here should update "input"         this.setstate({input: /* value child */ })     },      render: function() {         return(              <div>                 <div id='game'>                     <menu input={this.state.input}/>                 </div>             </div>         )     }   });   var menu = react.createclass({     render: function() {         return (             <div id='menu'>                 <input type="number" id="mynumber" value={this.props.input}> </input>                 <button id="mysetnumber" onclick={this.props.setsize}>try it</button>             </div>         )     } }) 

it can this:

var game = react.createclass({   changeinput: function(e) {     this.setstate({/* */})  },   render: function() {   return (     <div id="game">       <menu onvaluechange={this.changeinput} />     </div>     )   } });  var menu = react.createclass({   handlechange: function(e) {     this.props.onvaluechange(/* pass element or value */)   }   render: function() {    return (      <div id="menu">        <input onchange={this.handlechange}/>     </div>    )   } }) 

more or less should work. more see this. idea pass callback function parent child.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -