DEV Community

Discussion on: Introduction to Styled Components

Collapse
 
dance2die profile image
Sung M. Kim • Edited

When you pass a prop to DivWrapper, <DivWrapper color='blue'>...</DivWrapper>

styled will pass the prop and make it available auto"magically".

  const DivWrapper = styled.div`
    width: 50%;
    border: 2px solid black;
    ${props => (props.color === 'blue') ? `background-color: blue`: null}
    ${props => (props.color === 'red' ? `background-color: red`: null)}
  `;

And @ogwurujohnson , Shouldn't the color prop passed as my example above instead of like <DivWrapper color: 'blue'>?

Collapse
 
ogwurujohnson profile image
Johnson Ogwuru

Yeah, you are right. Lol was a typo. Would correct that immediately.