I'm using this example to set the height of the textarea.
but the size of the textarea is not set automatically if the textarea has a value.
https://codesandbox.io/s/autosize-textarea-forked-wdowvr?file=/src/App.tsx
import { useRef, useState } from "react";
import "./styles.css";
export default function App() {
const [value, setValue] = useState("");
const textAreaRef = useRef<HTMLTextAreaElement>(null);
const handleChange = (evt) => {
const val = evt.target?.value;
setValue(val);
};
return (
<div className="App">
<label htmlFor="review-text">Review:</label>
<textarea
id="review-text"
onChange={handleChange}
onInput={(e: React.FormEvent<HTMLTextAreaElement>) => {
e.currentTarget.style.height = e.currentTarget.scrollHeight + "px";
}}
ref={textAreaRef}
rows={1}
value={value}
/>
</div>
);
}
how can i fix this issue?