gpt4 book ai didi

reactjs - 您如何使用带样式的组件在 React Native 中为 Text 子项设置样式?

转载 作者:行者123 更新时间:2023-12-05 08:19:55 26 4
gpt4 key购买 nike

如果我有这个

const MyView = styled.View`
background: green;
color: red;
`

我有

<MyView>
<Text> Hello </Text>
</MyView>

文字不是红色

所以我试过了

const MyView = styled.View`
background: green;
& > Text { color: red; }
`

你可以在 React 中使用普通的样式组件来做到这一点,但是文本仍然不是红色

我如何实现这一目标?

我知道我能做到

const StyledText = styled.Text`
color: red;
`

然后

    <MyView>
<StyledText> Hello </StyledText>
</MyView>

但如果可以的话,我想避免这种情况。是否可以访问 RN 中的 Text 子元素?

最佳答案

不幸的是,RN 的样式化组件只是一个包装器,它返回带有样式属性 <View style={...styles} /> 的通用 RN View (或文本)。 .无法在父 block 中设置子项的样式。

关于reactjs - 您如何使用带样式的组件在 React Native 中为 Text 子项设置样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64353506/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com