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

Passing refs on React Native with TypeScript: (property) React.MutableRefObject.current: null Object is possibly 'null'.ts(2531)

$
0
0

I have several fields on a React Native form and I would like that the focus jump from one to the next one each time the user validate the field with the virtual keyboard.

I came up with something like that:

<NamedTextInput          name={'email'}          ref={emailRef}          ...          onSubmitEditing={() => passwordRef.current.focus()}        /><NamedTextInput          name={'password'}          ref={passwordRef}          ...        />

On current I get a TypeScript error:

(property) React.MutableRefObject<null>.current: nullObject is possibly 'null'.ts(2531)

I tried to add ! and ? marks but it ends into:

Property 'focus' does not exist on type 'never'.ts(2339)

Any idea to solve this ?

Thanks


Viewing all articles
Browse latest Browse all 6214

Trending Articles



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