Last active
August 5, 2018 01:06
-
-
Save daneden/d716273de0b802421bfb34f87ac9d17e to your computer and use it in GitHub Desktop.
styled-components will generate duplicative style declarations when props change the value for a rule. This is fine for e.g. the example below, where the ruleset is already small, but what if we have a dozen or more common styles for the two variants?
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
const Component = styled.div` | |
display: inline-block; | |
color: ${props => props.red ? 'red' : 'green'}; | |
` | |
export default Component |
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
/* Component.js will result in: */ | |
.foo { | |
display: inline-block; | |
color: red; | |
} | |
.bar { | |
display: inline-block; | |
color: green; | |
} | |
/* rather than: */ | |
.foo { | |
display: inline-block; | |
} | |
.bar { | |
color: red; | |
} | |
.baz { | |
color: green; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment