Last active
September 9, 2018 05:20
-
-
Save hg-pyun/1ce5fd9e05624a4edbc4f7d4a6354768 to your computer and use it in GitHub Desktop.
react v16.3.0 medium 04
This file contains 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
class FancyButton extends React.Component { | |
buttonRef = React.createRef(); | |
focus() { | |
this.buttonRef.current.focus(); | |
} | |
render() { | |
const {label, theme, ...rest} = this.props; | |
return ( | |
<button | |
{...rest} | |
className={`${theme}-button`} | |
ref={this.buttonRef}> | |
{label} | |
</button> | |
); | |
} | |
} | |
const FancyThemedButton = withTheme(FancyButton); | |
// We can render FancyThemedButton as if it were a FancyButton | |
// It will automatically receive the current "theme", | |
// And the HOC will pass through our other props. | |
<FancyThemedButton | |
label="Click me!" | |
onClick={handleClick} | |
/>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment