import { useEffect, type RefObject } from 'react' export function useAutoResizeTextarea( textareaRef: RefObject, value: string, maxRows: number ): void { useEffect(() => { const textarea = textareaRef.current if (!textarea) return textarea.style.height = 'auto' const lineHeight = parseFloat(getComputedStyle(textarea).lineHeight) || 24 const maxHeight = lineHeight * maxRows if (textarea.scrollHeight <= maxHeight) { textarea.style.height = `${textarea.scrollHeight}px` } else { textarea.style.height = `${maxHeight}px` } }, [textareaRef, value, maxRows]) }