mrkeyoor.com_
Tue 22 Sept 00:46 UTC
npmWeb Frontendupdated 21 Sept 2026

react-textarea-autosize review

react-textarea-autosize renders a real React `<textarea>` whose height follows its content. Standard textarea props and the DOM ref pass through, while `minRows`, `maxRows`, `onHeightChange`, and `cacheMeasurements` control sizing. The component measures computed font, padding, borders, and width through a hidden textarea, then writes the required height. Version 8.5.9 extends the peer range through React 19 and publishes condition-specific entries for browsers, workers, and edge runtimes. Our build produced 12 KB minified and 4.7 KB gzipped. The package remains CommonJS at its base and worked through both `require()` and ESM import in our test.

Verdict

react-textarea-autosize still solves the native-textarea case with a narrow API and a modest 4.7 KB gzip cost in our build. Prefer CSS `field-sizing` when browser support allows it, and avoid cached measurements in layouts whose fonts or width can change.

We installed it

Lab card: what happened when we installed react-textarea-autosizeScreenshot of react-textarea-autosize documentation
Install✓ · 1.9s6 packages on disk · 2 MB
ImportESM import works · require() works · CommonJS package with exports map
Browser4.7 KBgzipped (12 KB minified), bundled with esbuild
Typesno TypeScript types found
Known vulns00 critical · 0 high · 0 moderate · 0 low (npm audit)

Answers from our run

Does react-textarea-autosize install cleanly?

Yes. In a fresh container with an empty cache, npm install react-textarea-autosize finished in 2 seconds, leaving 6 packages and 2 MB on disk. npm audit reported no known vulnerabilities.

How much does react-textarea-autosize add to a browser bundle?

4.7 KB gzipped (12 KB minified) when the whole package is bundled for the browser with esbuild. Importing only part of it is usually smaller.

Does react-textarea-autosize work with both ESM and CommonJS?

Yes. Both import 'react-textarea-autosize' and require('react-textarea-autosize') worked in Node 22 in our run. The package is published as CommonJS with an exports map.

Does react-textarea-autosize include TypeScript types?

No type declarations were found in our install, so TypeScript users need their own declarations.

react-textarea-autosize or autosize: which should you use?

autosize: Use it outside React or when behavior must attach imperatively to existing textareas. react-textarea-autosize still solves the native-textarea case with a narrow API and a modest 4.7 KB gzip cost in our build.

When should you not use react-textarea-autosize?

Your browser matrix supports field-sizing: content. CSS can provide the same core behavior without React measurement code

API stability5/5The package adds only four sizing props and otherwise behaves like a native textarea. The 8.x surface has remained steady while the peer dependency range expanded through React 19. Refs, controlled values, events, accessibility attributes, and form names all follow the underlying element, which keeps upgrades away from application-specific adapters.
Docs2/5The README lists all four custom props, explains ref access, links a live demo, and includes the special `react-test-renderer` node mock. Its opening example still calls `React.renderComponent`, an API removed long ago, and it claims IE9 support. It does not explain font loading, width changes, box sizing, hydration shifts, overflow behavior, or measurement cache invalidation, which cause most integration surprises.
Maintenance2/5Package 8.5.9 and the repository's latest push both date to March 30, 2025. The project remains unarchived and the current package accepts React 19. GitHub also reports 69 open issues and pull requests with no newer push activity. The component's narrow scope reduces churn, yet teams waiting on a browser or React edge-case fix have weak evidence about response time.
Ecosystem4/5The npm endpoint counted 8,959,129 downloads in the latest completed week. The component accepts native textarea props and refs, so it works with ordinary forms and most React form libraries without a custom adapter. Its peer dependency spans React 16.8 through 19. There is no plugin system, and the same behavior is increasingly available through CSS or larger UI kits.

Use it if

  • A chat composer, comment box, or prompt field should grow with text while remaining a native textarea
  • Existing form code needs normal `value`, `onChange`, `name`, validation, focus, and selection behavior
  • The parent layout must react to exact pixel-height changes through `onHeightChange`
  • Your supported browsers do not all implement CSS `field-sizing: content`
Skip it if

Setup reality

We installed react-textarea-autosize 8.5.9 in a fresh Node 22 Bookworm container. npm finished in 1.9 seconds, leaving 6 packages and 2 MB on disk. The package declares 3 direct dependencies, one React peer dependency, 204 KB unpacked, an MIT license, and Node 10 or newer. npm audit found no known vulnerabilities at any severity. It is a CommonJS package with an exports map; both require() and ESM import worked. Our package inspection found no TypeScript types.

The browser build measured 12 KB minified and 4.7 KB gzipped with esbuild. No provider, stylesheet, credentials, or config file is required. The component copies computed textarea styles for measurement, so box-sizing, padding, borders, font metrics, and width all affect the result. Set resize: none if users should not fight the calculated height with the native drag handle. Past maxRows, choose an overflow style that keeps additional text reachable.

Web fonts and lazy CSS can arrive after the first measurement. A width change can also alter line wrapping without changing the value. Keep cacheMeasurements off when those inputs vary; when it is enabled, stale row height and sizing values are reused. There is no documented imperative recalculation method, so a controlled remount or state change is often required after fonts settle or a hidden panel becomes visible. Test the exact responsive containers used in production.

Server rendering produces textarea markup before a browser can measure it. The corrected height appears after hydration and may cause a small layout shift. Refs target the underlying DOM textarea, which helps focus and form libraries. For react-test-renderer, the README supplies createNodeMock because the renderer otherwise calls refs with null. The README's main render example uses an obsolete React API, so copy the prop table and component usage, not that mounting code.

Patterns

Build a controlled expanding field controlled-textarea

import TextareaAutosize from 'react-textarea-autosize'

function Composer({ value, setValue }) {
  return <TextareaAutosize value={value} onChange={e => setValue(e.target.value)} />
}

Standard textarea props pass through to the DOM element.

Set minimum and maximum rows bound-rows

<TextareaAutosize
  minRows={3}
  maxRows={10}
  value={message}
  onChange={event => setMessage(event.target.value)}
/>

Row pixels come from measured font metrics, so late font changes alter the real height represented by each row.

Keep browser resize controls out of the way style-resizing

<TextareaAutosize
  maxRows={8}
  style={{ boxSizing: 'border-box', resize: 'none', width: '100%', overflow: 'auto' }}
/>

Overflow keeps text reachable after `maxRows`; `resize: none` prevents conflicting manual inline height.

Keep a chat scroller pinned observe-height

<TextareaAutosize
  onHeightChange={(height, { rowHeight }) => {
    composerMetrics.current = { height, rowHeight }
    scroller.current?.scrollTo({ top: scroller.current.scrollHeight })
  }}
/>

The callback runs after the textarea height changes and provides the measured row height.

Cache measurements in a fixed layout cache-fixed-styles

<TextareaAutosize
  cacheMeasurements
  minRows={2}
  value={value}
  onChange={onChange}
/>

Leave caching disabled when width, fonts, padding, or borders can change after mount.

Focus the underlying textarea focus-ref

const inputRef = useRef(null)

<TextareaAutosize ref={inputRef} />
<button onClick={() => inputRef.current?.focus()}>Reply</button>

The forwarded ref is the actual DOM node, so selection and scroll methods work too.

Send on Enter and keep Shift+Enter submit-enter

<TextareaAutosize
  value={message}
  onChange={event => setMessage(event.target.value)}
  onKeyDown={event => {
    if (event.key === 'Enter' && !event.shiftKey) {
      event.preventDefault()
      send(message)
      setMessage('')
    }
  }}
/>

Clearing a controlled value returns the field to `minRows` on the next render.

Register it as a native form field react-hook-form

const { ref, ...field } = register('bio')

<TextareaAutosize {...field} ref={ref} minRows={4} />

Forwarded name, handlers, and ref let native-oriented form libraries use the component directly.

Remount after a web font loads remeasure-font

const [fontRevision, setFontRevision] = useState(0)
useEffect(() => {
  document.fonts?.ready.then(() => setFontRevision(value => value + 1))
}, [])

<TextareaAutosize key={fontRevision} value={value} onChange={onChange} />

The package has no documented recalculation method. Remounting discards measurements made with the fallback font.

Load the CommonJS entry commonjs-import

const TextareaAutosize = require('react-textarea-autosize').default

Our `require()` check worked, and CommonJS consumers receive the component on the default export.

Supply a textarea node in renderer tests renderer-test

const tree = renderer.create(<TextareaAutosize />, {
  createNodeMock: () => document.createElement('textarea'),
}).toJSON()

Without the node mock, `react-test-renderer` supplies a null ref and the component has no element to measure.

Replace JavaScript sizing where supported css-replacement

textarea {
  field-sizing: content;
  min-height: 3lh;
  max-height: 10lh;
  resize: none;
}

Verify `field-sizing` against the application's browser support policy before removing the component.

Alternatives

PackageRegistryPick it when
autosizenpmUse it outside React or when behavior must attach imperatively to existing textareas.
@mui/materialnpmUse MUI's included TextareaAutosize when the application already depends on that component system.
react-expanding-textareanpmUse it when its hook and component API better matches a smaller React form implementation.

More web frontend guides

postcss · react · react-dom · tailwindcss · htmlparser2 · tailwind-merge · the whole shelf →

How this guide is made: grounded in the library's documentation, release notes, changelog, and issue history, on a fixed rubric — not a hands-on install of every release. The 50 most-downloaded entries are additionally install-verified in clean containers. Corrections: contact the desk.