Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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