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

TypeScript issues when creating ref for React Native TextInput

$
0
0

I came across an issue when defining refs i.e.

inputRef = React.createRef(null)//...const someFunction () => { if (this.inputRef && this.inputRef.current) {   this.inputRef.current.focus() }}//...<TextInput ref={inputRef} />

When I access .focus() I get following error:

[ts] Property 'focus' does not exist on type 'never'. [2339]

Can I somehow tell createRef that this ref can be null or TextInput so it knows that .focus() may exist?


Viewing all articles
Browse latest Browse all 6314

Trending Articles