import { ChangeEventHandler, useEffect, useLayoutEffect, useRef } from "react"; import { Textarea } from "@/components/ui/textarea"; import { cn } from "@/util/utils"; type Props = { value: string; onChange?: ChangeEventHandler; className?: string; readOnly?: boolean; placeholder?: string; }; function AutoResizingTextarea({ value, onChange, className, readOnly, placeholder, }: Props) { const ref = useRef(null); useLayoutEffect(() => { // size the textarea correctly on first render if (!ref.current) { return; } ref.current.style.height = `${ref.current.scrollHeight + 2}px`; }, []); useEffect(() => { if (!ref.current) { return; } ref.current.style.height = "auto"; ref.current.style.height = `${ref.current.scrollHeight + 2}px`; }, [value]); return (