【问题标题】:Check multiple props with Styled-Components使用 Styled-Components 检查多个道具
【发布时间】:2023-03-06 10:48:01
【问题描述】:

使用 styled-components,我可以检查布尔属性是否为 true,然后添加如下 css:

const Box = styled.div`
  ${({ someProp }) =>
    someProp &&
    css`
      border: none;
  `};
`

但是如果我想检查多个条件怎么办?例如,我想检查someProp 是否为truesomeOtherProp 是否为false,我该怎么做?

我正在考虑做这样的事情,但语法似乎不正确:

const Box = styled.div`
  ${({ someProp, someOtherProp }) =>
    someProp && !someOtherProp
    css`
      border: 1px solid red;
  `};
`

【问题讨论】:

    标签: javascript styled-components


    【解决方案1】:

    const Box = styled.div`
      ${({ someProp, someOtherProp }) =>
        someProp && !someOtherProp &&
        css`
          border: 1px solid red;
      `};

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-19
      • 2020-03-05
      • 1970-01-01
      • 1970-01-01
      • 2019-10-07
      • 2019-11-26
      • 1970-01-01
      • 2022-08-18
      相关资源
      最近更新 更多