Skip to content

Instantly share code, notes, and snippets.

@hg-pyun
Last active September 9, 2018 05:20
Show Gist options
  • Save hg-pyun/1ce5fd9e05624a4edbc4f7d4a6354768 to your computer and use it in GitHub Desktop.
Save hg-pyun/1ce5fd9e05624a4edbc4f7d4a6354768 to your computer and use it in GitHub Desktop.
react v16.3.0 medium 04
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