我在自定义组件中访问 onChangeText 时遇到问题。这是我的组件的代码:
import React from 'react';
import {TextInput, StyleSheet} from 'react-native';
type Props=
{
style:any
}
const Input = (props:Props) =>
{
return <TextInput {...props} style = {{...styles.input, ...props.style}} blurOnSubmit autoCorrect = {false} keyboardType = "number-pad" maxLength = {2} />
}
const styles = StyleSheet.create({
input:{
height:30,
borderBottomColor: 'grey',
borderBottomWidth: 1,
marginVertical: 10
}
})
export default Input;`
这是我正在使用的另一个文件中的代码部分:
<Input style = {styles.input} onChangeText = {numberInputHandler} value = {enteredValue} />
OnChangeText 带有下划线,错误是“IntrinsicAttributes & Props”类型上不存在属性“onChangeText”。我在一个教程中看到,在我的自定义组件中键入 {...props} 后,可以访问它的 props,但是家伙正在用 js 编写,而我在 ts 中。感谢帮助!