Skip to content

Instantly share code, notes, and snippets.

@inPhoenix
Last active December 1, 2018 11:01
Show Gist options
  • Save inPhoenix/18387b7c01e1c5c6b5697657602fa3c9 to your computer and use it in GitHub Desktop.
Save inPhoenix/18387b7c01e1c5c6b5697657602fa3c9 to your computer and use it in GitHub Desktop.
React ES6 stage2 autobinding Arrow Function with parameters
// Example using create-react-app.
// For scratch configurations, add babel-plugin-transform-class-properties.
// More info: https://babeljs.io/docs/plugins/transform-class-properties/
import React from 'react'
class Example extends React.Component {
example = (param) => () => {
console.log('Hello ', param)
}
render() {
return (
<div>
<button onClick={this.example('World')} />
</div>
)
}
}
export default Example
// With the event object
class App extends Component {
handleMouse = text => e => {
console.log("hello", text, e.screenX, e.screenY)
}
render() {
return (
<div>
<div onMouseMove={this.handleMouse("world")}>
Example
</div>
</div>
)
}
}
export default App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment