简体   繁体   中英

Styled Component multiple props (React Native)

I am using Styled Components with my React Native app and I am trying to figure out how to use multiple props.

My Component :

<SelectedPill active={true} color={'red'}>Text Here</SelectedPill>

My Styled Component :

const SelectedPill = styled.TouchableOpacity`
  ${({active}) => active && `
    background: ${props => (props.color ? props.color : '#292929')};
  `};
`

What I'm trying to do in the styled component is that if the prop "active" is set to true, then get the "color" props int he components and apply it.

This should work:

const SelectedPill = styled.TouchableOpacity`
   ${({active, color}) => active && `
      background: ${color ? color : 'red'};
   `};
`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM