Created
June 1, 2020 23:16
-
-
Save tonymtz/ff22d27744ed168975b28ff7247e94a0 to your computer and use it in GitHub Desktop.
Composition over inheritance code example
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
// 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