I have created a TextArea and set up a ref. I added a button which randomly assigns value to the ref. however when I mouse over on it, the value disappears.
const textareaRef = React.useRef(null);
const onAddFeature = () => {
if (textareaRef.current) {
//@ts-ignore
textareaRef.current.value = Math.random().toString(32);
}
<Textarea
ref={textareaRef}
onChange={(e) => console.log(e.target.value)}
size="sm"
/>
<Button
onPress={onAddFeature}
isIconOnly
size="sm"
variant="solid"
color="primary"
/>
I tried the ref. It doesn't work not only on the TextArea component but also on the Input component.
I believe the TextArea component might have an internal value state which is not updated with your use of the ref. After a render the value is returned to the internal value state.
The proper way to accomplish what you want is to use useState instead of useRef and pass in a value prop to TextArea.