[英]setNativeProps for TextInput in React Native
How do I know what native props are available for a component to use setNativeProps
. 我如何知道哪些本机道具可用于组件使用
setNativeProps
。 In this example, the <TextInput>
component doesn't have text
as a prop but apparently setNativeProps
use text
instead of value
as a prop. 在此示例中,
<TextInput>
组件没有text
作为道具,但显然setNativeProps
使用text
而不是value
作为道具。 Thank you! 谢谢!
clearText = () => {
this._textInput.setNativeProps({text: ''});
}
render() {
return (
<View style={{flex: 1}}>
<TextInput
ref={component => this._textInput = component}
/>
<TouchableOpacity onPress={this.clearText}>
<Text>Clear text</Text>
</TouchableOpacity>
</View>
);
}
}
This is pretty common in react-native, due to limited documentation. 由于文档有限,这在React-native中很常见。 Whenever looking for any information regarding react-native components, it is a good idea to simply look at the .js file you are using.
每当查找有关本机组件的任何信息时,最好仅查看正在使用的.js文件。 In this case, TextInput, can be found...
在这种情况下,可以找到TextInput ...
Project/node_modules/react-native/Libraries/Components/TextInput/TextInput.js
Hope you can find what you're looking for - with a bit of digging. 希望您能找到所需的内容-进行一些挖掘。 If you want to look further, looking into the RCT files is a good idea also.
如果您想进一步了解,那么研究RCT文件也是一个好主意。
Project/node_modules/react-native/Libraries/Text/RCTTextField.h
Project/node_modules/react-native/Libraries/Text/RCTTextView.h
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.