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?