【问题标题】:Style Link with styled components带有样式组件的样式链接
【发布时间】:2020-03-14 23:08:59
【问题描述】:

我在 TypeScript React 应用程序中使用 styled-components,并且在它上面有一个路由器。

是否可以使用带样式的组件对 react-router-dom 中的 Link 元素进行样式设置?

可能是这样的:

  const HeaderLink = styled.Link`
    background-color: hotpink;
  `

【问题讨论】:

    标签: javascript reactjs typescript react-router styled-components


    【解决方案1】:

    有可能,只需将Link 作为参数传递给styled 函数:

    const StyledLink = styled(Link)`
       color: green;
    `;
    

    【讨论】:

    • 记得import { Link } from 'react-router-dom'
    猜你喜欢
    • 2018-10-16
    • 2021-12-16
    • 1970-01-01
    • 2020-01-17
    • 2019-08-20
    • 2012-01-20
    • 2018-07-26
    • 1970-01-01
    • 2016-12-30
    相关资源
    最近更新 更多