Reputation: 459
I am trying to use useRef on my TextInput like this:
<TextInput
ref={commentRef}
defaultValue={`${postComment}`}
placeholder={
addLinkToArticleStatus
? 'Attach link to an existing article'
: 'Comment or ask specific question'
}
placeholderTextColor="gray"
/>
I have function which shall read the value from the ref
. And for now I am doing it like this
const addNewComment = () => {
console.log('--commentRef--', commentRef.current.value);
};
But It is always giving me undefined and I don't understand why. Any suggestions please?
Upvotes: 0
Views: 142
Reputation: 1549
Try initialize it with null. i.e:
const commentRef = React.useRef(null);
Or use createRef:
const commentRef = React.createRef();
Upvotes: 1