小编Cri*_*ano的帖子

如何将自定义属性传递给功能组件中的样式组件?

我试图了解这件事是如何工作的,但我发现的所有示例都是以课堂方式编写的。

   import React from 'react'
   import styled from 'styled-components/native'

   const MyTag = styled.Button.attrs({
     title: myThisThingValue
   })`
     // some style
     background: thisIsAlsoMyThingValue
   \` 

   export default function MyComponent({ props }) {
     return(
       <MyTag myThisThing="My value" thisIsAlsoMyThing="Other Value" />
         )
   }

Run Code Online (Sandbox Code Playgroud)

我只想访问 MyTag 样式中的自定义属性。我(props) => {title: props.MyThing }在 .attrs() 中使用了 a但没有用。

javascript reactjs react-native react-native-android styled-components

5
推荐指数
2
解决办法
8761
查看次数