如何在react-naive中获取onPress中的Text组件值 [英] How to get Text component value onPress in react-naive
本文介绍了如何在react-naive中获取onPress中的Text组件值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是一名新的 react-native 开发人员.我想使用 onPress 获取 Text 组件的值并将其传递给函数.
I'm a new react-native developer. I want to get the value of Text component using onPress and pass it to a function.
<Text onPress={()=>this.display}>Hello World</Text>
display= (text) =>{
console.log(text);//this should print Hello world
}
推荐答案
该方法可用于从文本 onPress 事件中获取文本
This method can be used to get text from a text onPress event
<Text onPress={(event) => console.log(event._dispatchInstances.memoizedProps.children)} >{value}</Text>
这篇关于如何在react-naive中获取onPress中的Text组件值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文