尝试在 react native 的自定义组件中使用两个 props,但它不起作用



我正在向我的自定义组件添加两个道具(textProp和imgProp(,但我一直收到这个错误<Image> component cant contain children。这就是我目前拥有的

function TextImg(textprop, imgprop) {
return(
<div>
<div>
<Text>{textprop.text}</Text>
</div>
<div>
<Image source={imgprop.imageUri}>!</Image>
</div>
</div>
);
}

有人能帮我吗,谢谢!

图像(img(被视为空元素,并且是自关闭的,需要符合html规范。

https://developer.mozilla.org/en-US/docs/Glossary/Empty_element

react native Image也有同样的限制。

它们不能包装任何内容或具有任何子节点。"quot;是个问题。

<Image source={imgprop.imageUri}>!</Image>

改为尝试

<Image source={imgprop.imageUri} />

如果您需要显示一个"那么它必须在图像之外。

如果您需要显示"quot;在图像中,

尝试

<View>
<Image source={img} />
<Text
style={{
position: "absolute",
// some stylng
}}
>
!
</Text>
</View>

最新更新