React Animate Height is a lightweight, dependency-free (beyond React itself) component designed for animating the height of elements using CSS transitions. It enables developers to smoothly slide elements up to `0`, down to `auto`, or to any specific pixel or percentage height. The current stable version is 3.2.3, which is built with React Hooks, requiring React 16.8 or newer. The library appears to be actively maintained, with 'Version 3' indicating significant updates and ongoing support. A key differentiator is its focused approach to height animation, offering optional opacity transitions and control over CSS classes at various animation states, without the overhead of a full-fledged animation library. It is often chosen for its simplicity and direct control over height transitions in React applications, especially when `auto` height animation is required, which can be complex with pure CSS.
npm install react-animate-heightVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to use `react-animate-height` to create an expandable and collapsible content panel. It utilizes React's `useState` hook to manage the target height ('0' for collapsed, 'auto' for expanded) and a button to toggle between these states, showcasing basic setup and prop usage.
Update your callback prop names from `onAnimationStart` to `onHeightAnimationStart` and `onAnimationEnd` to `onHeightAnimationEnd`.
Place custom styling that affects layout on an inner element, or ensure that `className` and `style` props for `AnimateHeight` itself only apply non-layout-altering styles (e.g., `background`, `padding`, `margin`). The component internally handles `height` and `overflow`.
Ensure your project uses `react` and `react-dom` versions 16.8.0 or higher. Update your `package.json` peer dependencies if necessary.
Change your import statement to `import AnimateHeight from 'react-animate-height';`.
Ensure that the children passed to `AnimateHeight` are standard React elements (JSX) or components, not functions. If you intend to render based on animation state, use callback props like `onHeightAnimationEnd`.
Upgrade your React version to 16.8.0 or higher. You may need to update `react` and `react-dom` in your `package.json`.