Skip to content

Instantly share code, notes, and snippets.

@szy0syz
Created January 9, 2020 04:05
Show Gist options
  • Save szy0syz/2604af964f8743270057a8496aca677b to your computer and use it in GitHub Desktop.
Save szy0syz/2604af964f8743270057a8496aca677b to your computer and use it in GitHub Desktop.
Reusing CSS With Styled Components
import styled, { css } from ‘styled-components’;
export const DefaultInput = styled.input`
border: 1px solid ${({error})=>( error ? `red` : `grey` )};
border-radius: 4px;
outline: none;
padding: 0.5em;
`;
export const SecondComponent = styled(DefaultInput)`
/* make changes as needed*/
`;
const baseInputStyles = css`
border: 1px solid ${({error})=>( error ? `red` : `grey` )};
border-radius: 4px;
outline: none;
padding: 0.5em;
`;
export const DefaultInput = styled.input`
${baseInputStyles}
`;
export const SecondComponent = styled.button`
${baseInputStyles}
/* make changes as needed*/
`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment