См. Область применения :
// (a,b) are parameters passed by `Component` to `onClick` handler.
<Component onClick={(a,b) => this.doSomething(d)}/>
// Simple class example
class App extends React.Component {
doSomething = (a,b) => {
console.log('a',a,'b',b);
}
render() {
// onClick={this.doSomething}
return <Component onClick={(a,b) => this.doSomething(a,b)}/>
}
}
class Component extends React.Component {
coolClick = () => {
this.props.doSomething('hello','world')
}
render() {
return <button onClick={this.coolClick}>Active doSomething</button>
}
}
// d is a parameter available in the current scope
<Component onClick={() => this.doSomething(d)}
// Simple examples of possible scopes
import { d } from './consts'
const d = 5;
class App extends React.Component {
doSomething = (x) => {
console.log('x',x);
}
render() {
const d = 5;
return <Component onClick={() => this.doSomething(d)}/>
}
}