Skip to content

Instantly share code, notes, and snippets.

@vjwilson
Created June 3, 2017 14:36
Show Gist options
  • Save vjwilson/007560ce278eedbb72c216aceabde624 to your computer and use it in GitHub Desktop.
Save vjwilson/007560ce278eedbb72c216aceabde624 to your computer and use it in GitHub Desktop.
Two alternatives for wrapping a button element in a React component
// Option 1, more like HTML button
class PrimaryButton extends React.Component {
render() {
return (
<button onClick={this.props.action}>{this.props.children}</button>
);
}
}
// Option 1 usage
<PrimaryButton action="saveUser">Save User</PrimaryButton>
// ------------------- VS. -------------------
// Option 2, all options specified as attributes
// (seems like this is very common in the React community)
class SecondaryButton extends React.Component {
render() {
return (
<button onClick={this.props.action}>{this.props.text}</button>
);
}
}
// Option 2 usage
<SecondaryButton action="saveUser" text="Save User" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment