如何在react-naive中获取按下时的文本组件值

Ism*_* Ch 2 javascript reactjs react-native react-props

我是一名新的 React-Native 开发人员。我想使用 onPress 获取 Text 组件的值并将其传递给函数。

<Text onPress={()=>this.display}>Hello World</Text>


display= (text) =>{
    console.log(text);//this should print Hello world
  }
Run Code Online (Sandbox Code Playgroud)

小智 8

此方法可用于从文本 onPress 事件获取文本

 <Text onPress={(event) => console.log(event._dispatchInstances.memoizedProps.children)} >{value}</Text>
Run Code Online (Sandbox Code Playgroud)