react-textarea-autosize is a React component that serves as a high-performance, lightweight (approx. 1.3KB minified & gzipped) drop-in replacement for the native `<textarea>` HTML element, automatically adjusting its height to fit its content. Inspired by the popular jQuery Autosize plugin, it provides a seamless user experience for input fields that need to expand dynamically. The package is currently at version 8.5.9 and maintains an active release cadence with frequent patch updates to address bugs and improve compatibility. Key differentiators include its small size, broad React compatibility (supporting React 16.8.0 through 19.0.0), and specific features like `minRows`, `maxRows`, and an `onHeightChange` callback. Recent enhancements have focused on improving module resolution for modern JavaScript runtimes such as Vercel Edge and Cloudflare Workers, resolving race conditions, and bolstering Node.js ESM support.
npm install react-textarea-autosizeVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to integrate `TextareaAutosize` into a React application, showing basic usage with state management, `minRows`, `maxRows`, and the `onHeightChange` callback.
Ensure you are using `react-textarea-autosize@8.5.0` or higher for improved Node.js ESM compatibility and consistent module loading. Always use `import TextareaAutosize from 'react-textarea-autosize';` in ESM contexts.
To correctly test refs that point to the internal textarea element, provide a `createNodeMock` option to `renderer.create`, e.g., `renderer.create(<TextareaAutosize />, { createNodeMock: () => document.createElement('textarea') })`.Avoid applying `display: flex`, `display: grid`, `display: inline`, or other conflicting layout properties directly to `TextareaAutosize` if they interfere with the internal `display: block` of the hidden sizing element. Ensure global or parent styles do not inadvertently override its critical sizing properties. Update to `v8.5.4` or higher which includes a fix to force `display: block`.
Update to `react-textarea-autosize@8.5.8` or higher to resolve race conditions related to asynchronous operations and component unmounting.
Upgrade to `react-textarea-autosize@8.5.8` or later to include the fix for this race condition.
Verify that no custom CSS is overriding essential layout properties on the `TextareaAutosize` component. For form reset issues, ensure you are using `react-textarea-autosize@8.5.7` or newer, which fixed this specific problem.
When using `react-test-renderer`, pass the `createNodeMock` option to `renderer.create` to mock DOM elements for refs, e.g., `renderer.create(<TextareaAutosize />, { createNodeMock: () => document.createElement('textarea') })`.