You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native中如何获取标签组件的内部文本值?

在React Native中获取Text组件的内部文本

在React Native里,JSX元素本质是普通JavaScript对象,不存在Web端DOM元素的innerHTML属性。要获取<Text>组件的内部文本,直接访问其props.children即可。

基础用法示例

针对你提供的数组,直接通过props.children提取文本:

const tagArray = [<Text>Text1</Text>, <Text>Text2</Text>, <Text>Text3</Text>];
const innerText = tagArray[0].props.children; // 输出: Text1

补充说明

React Native的<Text>组件会把内部文本作为props.children传递,只要组件没有嵌套复杂结构(比如多层嵌套Text或其他组件),直接读取props.children就能拿到你需要的文本内容。

内容的提问来源于stack exchange,提问作者Benevos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 00:11:58