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

Use component name as a type of React.Ref

$
0
0

I have an component called TextInput extending React-native's TextInput.I founded that the component name is used as a type of Ref:const ref = useRef<TextInput | null>(null)

How can I achieve this (without using typeof)?

Below is my code:

export interface TextInputProps  extends ComponentPropsWithRef<typeof RNTextInput>,    RNTextInputProps {}const TextInputComponent = forwardRef<RNTextInput, TextInputProps>(  ({ style, ...rest }: TextInputProps, ref: Ref<RNTextInput>) => {    return (<RNTextInput        ref={ref}        style={[styles.textInput, style]}        {...rest}      />    );  },);const TextInput = memo(TextInputComponent);TextInput.displayName = 'TextInput';export default TextInput;

I looked up at others code, but still did not get it


Viewing all articles
Browse latest Browse all 6291

Trending Articles



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