Quantcast
Viewing all articles
Browse latest Browse all 6404

useRef.current is undefined in a React Native functional component

I'm trying to focus a text input field once the user clicks a button. The code looks as follows:

const refName = React.useRef();const changeFocus = () => {    refName.current.focus();}

with the text input having an attribute ref defined as refName.This gives me an error (undefined is not an object (evaluating 'refName.current.focus')), and when I rewrite the changeFocus function as console.log(refName) this is what I get:

Object {"current": undefined,}

I'm not sure how else I'm supposed to define the reference or how else to approach this problem.Thanks


Viewing all articles
Browse latest Browse all 6404

Trending Articles