Answer the question
In order to leave comments, you need to log in
React - how to implement parent function call?
Got a question. I just can't get it to work
. I have 2
Parent Components:
<Children
info={this.props.info}
hire={(id) => () => {console.log('testing')}}
/>
<button onClick={this.handleClick(), this.props.hire(id)} }>Bla</button>
{this.props.workers && this.props.workers.map( (worker) => {
return (<div className="large-4 column"><Worker
info={worker}
selected={false}
hire={(id) => () => {console.log('and here ' + id)}}
/></div>);
})}
<div style={{cursor: 'pointer'}} onClick={function bla() {this.handleColor(); hire(5); console.log('function');}.bind(this)}>
Answer the question
In order to leave comments, you need to log in
Formally, it turns out that you have one level of nesting of functions superfluous, there is an expectation that when you call hire (5) something should fall into the console, then
either
this.handleColor();
hire(5)();
console.log('function');
Everything is correct in Parent, but in Children you can do this:
In render: onClick={this.onClick.bind(this)}
and this method:
onClick () {
this.props.hire();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question