, , , , .
. , Arrow. Arrow function, everytime, , bind.
<div onClick={()=>{this.onClick()}}>Previous</div>
, , this.onClick.
onClick = () => {
console.log("Div is clicked")
}
, React An arrow function does not have its own this; the this value of the enclosing execution context is used. . binding works is constructor. proposed class fields for arrow functions, ES6,
, , , , . , this question .
Arrow function prevItem, , , React.
prevItem = () => {
console.log("Div is clicked")
}
render(){
return (
<SecondClass prevItem={this.prevItem} />
)
}
, prevItem , using bind or arrow function, prevItem i.e Main.js React. prevItem - ,
<ThirdClass type="prev" onClick={()=>this.props.prevItem()} />
<div onClick={()=>{this.props.onClick()}}>Previous</div>
, SecondClass ThirdClass . ,
<ThirdClass type="prev" onClick={this.props.prevItem} />
<div onClick={this.props.onClick}>Previous</div>
.
, ThirdClass SecondClass, Arrow function bind in render. How to Avoid binding in Render method