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

React Native: Using `useRef()` on extended component

$
0
0

I want to use useRef() on my extended component.

const ref = useRef<TextInputProps>(null);

This is the TextInputProps:

export type TextInputProps = ThemeProps & DefaultTextInput['props'] & InputProps;

This is my element:

<Input ref={ref} onFocus={onMainTextInputFocus} placeholder={placeholder ?? '-- Select --'} value={selectedLabel} />

This is my Input component:

export function Input(props: TextInputProps) {    ....

This is the error:

(property) ref: React.RefObject Type '{ ref:RefObject; onFocus: () => void; placeholder: string;value: string | undefined; }' is not assignable to type'IntrinsicAttributes & ThemeProps & Readonly &Readonly<{ children?: ReactNode; }> & InputProps'. Property 'ref'does not exist on type 'IntrinsicAttributes & ThemeProps &Readonly & Readonly<{ children?: ReactNode; }> &InputProps'.

How do I fix this?


Viewing all articles
Browse latest Browse all 6287

Trending Articles