【发布时间】:2019-05-10 18:40:43
【问题描述】:
我正在努力挠头;试图找出下面的 sn-p 出了什么问题。
import React from 'react';
import { Text, TouchableOpacity, View } from 'react-native';
class MyButton extends React.Component {
setNativeProps = (nativeProps) => {
alert(JSON.stringify(this._root.props)) //able to get this.v here
}
render() {
return (
<View ref={cc => {this._root = cc; this.v = 100 }} me="tom">
<Text ref={component => { this._root1 = component;}} style={{margin:55}} onPress={()=>this.setNativeProps({text:'fgfg'})}>{this.props.label} </Text>
</View>
)
}
}
export default class App extends React.Component {
render() {
return (
<TouchableOpacity >
<MyButton label="Press me!" />
</TouchableOpacity>
)
}
}
基本上尝试使用 ref 回调
从<View> 元素(即this._root.props)获取道具
尽管this._root1.props 一直都可以正常工作。
有人可以帮我弄清楚它有什么问题吗?
编辑:
我什至可以看到this._root,但我什至看不到 this._root.props.me。
【问题讨论】:
标签: react-native view prop