# useExpandable

> A custom React hook for creating smooth expandable/collapsible elements with spring animations using Framer Motion.  Parameters - `initialState` (boolean, optional): Initial expansion state. Defaults to `false`.  Returns The hook returns an object with the following properties:  - `isExpanded` (boolean): Current expansion state - `toggleExpand` (function): Function to toggle the expansion state - `animatedHeight` (MotionValue): Framer Motion value for animated height  Features - Spring-based animations for smooth transitions - Zero-to-auto height animations - Configurable initial state - TypeScript support - Built with Framer Motion for reliable performance

- Author: [Prism UI](https://21st.dev/@Codehagen)
- Library: [Prism UI](https://21st.dev/@Codehagen/library/prism-ui)
- License: mit
- Tags: Hook
- npm dependencies: framer-motion
- Live preview: https://21st.dev/@Codehagen/components/use-expandable

## Install

```bash
npx shadcn@latest add "https://21st.dev/r/Codehagen/use-expandable?api_key=$API_KEY_21ST"
```

Requires a 21st API key (generate one at https://21st.dev/mcp) passed as `API_KEY_21ST`. Free accounts get a limited number of installs per day; unlimited on a paid plan — see https://21st.dev/pricing.

Full component directory: https://21st.dev/llms.txt · More like this: https://21st.dev/community/components/s/hook.md
