React Native TextInput onChange event type not matching onChange prop

  Kiến thức lập trình

I am trying to create a custom component with react native TextInput component, and passing onChange props down to TextInput alongside some other code, but the event type is wrong according to typescript.

CustomComponent:

export default function Input(props) {
  return
  <TextInput
    placeholder=(props.placeholder)
    onChange={(e) => {
      setText(e.nativeEvent.text)

      if(props.onChange) props.onChange(e)
    }}
  />
}

But typescript says:

Argument of type 'NativeSyntheticEvent<TextInputChangeEventData>' is not assignable to parameter of type 'ChangeEvent<TextInputProps>'.
  Types of property 'target' are incompatible.
    Type 'Component<unknown, {}, any> & Readonly<NativeMethods>' is not assignable to type 'EventTarget & TextInputProps'.
      Type 'Component<unknown, {}, any> & Readonly<NativeMethods>' is missing the following properties from type 'EventTarget': addEventListener, dispatchEvent, removeEventListenerts(2345)
(parameter) e: NativeSyntheticEvent<TextInputChangeEventData>

Tried changing types and looking online for similar problems but no success

LEAVE A COMMENT