javascript - Trouble with printing parent state from child (ReactJS) -
i'm attempting use parent control editor component , save component. parent component has these functions:
constructor() { super(); this.state = { code: "", current_program: 'new' } } updatecode(event) { this.setstate({ code: event }); } save() { console.log(this.state.code); }
in it's render component, have this:
<ide code={this.state.code} updatecode={this.updatecode}/> <browser save={this.save.bind(this)} programs={this.props.programs} />
the ide calls update, , when log output updatecode function in parent, works properly. but... in browser component, have following:
<button classname="width-30" bsstyle="primary" onclick={() => this.props.save()}> <glyphicon glyph="save" /> save </button>
on click, prints "", have fact bound "this" before code in parent state updated? printing old state? how can make update? thanks.
edit: i'm calling ide component: onchange={this.props.updatecode.bind(this)}
solved it: binding state of child in ide component, meant updating, changing implementation of ide component in parent following: <ide code={this.state.code} updatecode={this.updatecode.bind(this)}/>
, allowed states update properly
Comments
Post a Comment