Skip to content

Instantly share code, notes, and snippets.

@daneden
Last active August 5, 2018 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daneden/d716273de0b802421bfb34f87ac9d17e to your computer and use it in GitHub Desktop.
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?
const Component = styled.div`
display: inline-block;
color: ${props => props.red ? 'red' : 'green'};
`
export default Component
/* 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