I've got a problem with access to onChangeText in my custom component. Here is the code of my component:
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;`
And here is the part of code in another file where i'm using it:
<Input style = {styles.input} onChangeText = {numberInputHandler} value = {enteredValue} />
OnChangeText is underlined and the error is Property 'onChangeText' does not exist on type 'IntrinsicAttributes & Props'. I see in a tutorial that after typing {...props} in my custom component inside there is access to its props, but guy is writing in js and I'm in in ts. Thanks for help!
You have to tell Typescript that in props there is a function called 'onChangeText', so you have to add it to your Props type: