Skip to content

Instantly share code, notes, and snippets.

@pramendra
Created March 6, 2018 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pramendra/05003d435af216ffda6d72aa970eaebb to your computer and use it in GitHub Desktop.
Save pramendra/05003d435af216ffda6d72aa970eaebb to your computer and use it in GitHub Desktop.

Styled component use case

Styled component as standard react component

avoid creating middleware react component

before

const StyledIcon = styled(Icon)``; export const HomeIcon = () => ;

after

export const CameraIcon = styled(Icon)``; CameraIcon.defaultProps = { uri: 'btn-sell.svg', };

advantage: can avoid creating react component in the middle

As default component

before

const StyledButton = styled.buttonborderradius: 2; border: 0; background: none;;

export const Button = ({ children, onClick = () => {} }: buttonType) => ( {children} );

after

export const Button = styled.buttonborder: 0; background: none;;

advantage: code is simple and more readable

Inheritance

export const PlainButton = Display2.withComponent(CoreButton).extendpadding: 5px 10px;;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment