Created
February 29, 2016 21:55
-
-
Save JavascriptMick/0417a99bb932bbacf5e6 to your computer and use it in GitHub Desktop.
Use a Higher order component to add mouse events to a host component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
export default function GetNasty(TargetComponent){ | |
return class GetNasty extends React.Component{ | |
handleOnClick($event){ | |
alert("You suck!"); | |
} | |
render(){ | |
const props = Object.assign({ | |
onClick: this.handleOnClick | |
}, this.props); | |
return (<TargetComponent {...props}/>); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not really happy with the use of {..this.props} on the render method of the host component (Button)