Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Custom TextInput getting error with React.forwardRef?

$
0
0

I have a simple custom component as below

import {View, TextInput} from 'react-native'interface ICustomProps extends TextInputProps {  iconName?: WhateverType;}const CustomInput: React.FC<ICustomProps> = React.forwardRef((props, ref) => {  const [someState, setSomeState] = useState(false);  return (<View>      {props.iconName && renderIcon()}<TextInput         ref={ref}        {...props}      /></View>  )})export default CustomInput

With the code above, i'm expecting it to be able to work as I would like to implement auto focus for the textinput, however, im getting below error when I define ref

No overload matches this call.  Overload 1 of 2, '(props: TextInputProps | Readonly<TextInputProps>): TextInput', gave the following error.    Type 'ForwardedRef<unknown>' is not assignable to type 'LegacyRef<TextInput> | undefined'.      Type 'MutableRefObject<unknown>' is not assignable to type 'LegacyRef<TextInput> | undefined'.        Type 'MutableRefObject<unknown>' is not assignable to type 'RefObject<TextInput>'.          Types of property 'current' are incompatible.            Type 'unknown' is not assignable to type 'TextInput | null'.              Type 'unknown' is not assignable to type 'TextInput'.  Overload 2 of 2, '(props: TextInputProps, context: any): TextInput', gave the following error.

Cant seems to be able to understand which part of the component gone wrong, appreciate some help here


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>