【问题标题】:How to convert this function from the styled components package to regular jsx如何将此功能从样式化组件包转换为常规 jsx
【发布时间】:2021-05-30 01:23:12
【问题描述】:

我目前正在从我的 react 应用程序中删除样式化组件。但是我在使用下面的功能时遇到了一些问题。有没有人有什么建议?要清楚一点。此函数设置不透明度和过滤模糊。我需要它来做同样的事情,就在普通的 JSX 中。

const ImgSrc = styled.div.attrs(props => ({
  style: {
            opacity: `${props.opacity}`,
            filter: `${props.filter}`
         }
}))

【问题讨论】:

    标签: reactjs react-native styled-components


    【解决方案1】:

    您可以简单地将ImgSrc 写成一个组件,它返回具有指定属性的 div,例如

    const ImgSrc = props => (
      <div styles={{
                opacity: props.opacity,
                filter: props.filter
       }} />
    )
    

    【讨论】:

    • 谢谢 Shubham,我会试试看的。
    猜你喜欢
    • 2021-03-06
    • 2019-09-26
    • 1970-01-01
    • 2020-06-29
    • 2021-04-13
    • 1970-01-01
    • 2017-03-30
    • 1970-01-01
    • 2021-08-24
    相关资源
    最近更新 更多