Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tonymtz/ff22d27744ed168975b28ff7247e94a0 to your computer and use it in GitHub Desktop.
Save tonymtz/ff22d27744ed168975b28ff7247e94a0 to your computer and use it in GitHub Desktop.
Composition over inheritance code example
// Ugly way
const Text = () => {
// ... some implementation ...
}
class H1 extends Text {
// ... override some implementation ...
}
class H2 extends H1 {
// ... override some implementation ...
}
// Best way
const Text = () => {
// ... some implementation ...
}
const H1 = props => <Text tag="h1" {...props} />;
const H2 = props => <Text tag="h2" {...props} />;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment