Skip to content

Instantly share code, notes, and snippets.

@vnys
Last active April 20, 2020 09:31
Show Gist options
  • Save vnys/511198e23de26471df3176bd2f9aba41 to your computer and use it in GitHub Desktop.
Save vnys/511198e23de26471df3176bd2f9aba41 to your computer and use it in GitHub Desktop.
adding props to styled components

Sometimes it’s useful to extend an existing component and add style props similar to styled-system

const addMarginRightProp = () => ({ marginRight }) =>
  marginRight && { marginRight: `${marginRight}px` }

const IconWithMarginProp = styled(Icon)(addMarginRightProp)
const ButtonWithMarginProp = styled(Button)(addMarginRightProp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment