conditional rendering in styled components

后端 未结 5 2204
失恋的感觉
失恋的感觉 2020-12-07 14:19

How can I use conditional rendering in styled-components to set my button class to active using styled-components in React?

In css I would do it similarly to this:<

5条回答
  •  离开以前
    2020-12-07 14:56

    You can simply do this

    
    

    And in your styles something like this:

    const Tab = styled.button`
      width: 100%;
      outline: 0;
      border: 0;
      height: 100%;
      justify-content: center;
      align-items: center;
      line-height: 0.2;
    
      ${({ active }) => active && `
        background: blue;
      `}
    `;
    

提交回复
热议问题