Try it
Preparing the example…
Shortest usage
<MotionList as="ul" items={todos} renderItem={(todo) => <TodoRow todo={todo} />} />;What it handles for you
- New items enter with a bounded stagger while untouched items stay still.
- Removed items leave the flow and animate out where they were while the rest slide into the gap.
- Reordered items glide to their new positions.
- Moves interrupted by another change keep their velocity.
present={false}animates every item out, andplayKeyreplays the entrance.
Use it for
- A todo list.
- Filtered search results.
- A shopping cart.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
items | readonly T[] | —required | Your data array. |
getKey | (item) => string | number | item.id | Returns a unique, stable key for an item. Defaults to item.id, or the item itself for strings and numbers. |
renderItem | (item, index) => ReactNode | item.label | Draws an item. |
as | element | 'div' | The element to render. |
itemAs | element | 'li' | 'div' | The element for each item. |
itemClassName | string | Class for each item element; itemStyle sets its inline style. | |
effect | 'rise' | 'fade' | 'scale' | 'slide' | 'rise' | How items enter and leave. |
distance | number | 16 | Travel of rise and slide in pixels. |
stagger | number | 40 | Milliseconds between entering items. |
order | 'forward' | 'reverse' | 'forward' | Direction of the stagger. |
present | boolean | true | false animates every item out while keeping the layout; true brings them back. |
initial | boolean | true | Play the entrance when the list mounts. |
playKey | string | number | Changing it replays the entrance. | |
transition | Transition | spring | Transition for entering and leaving items. |
layoutTransition | Transition | spring | Transition for items gliding to new positions. |
Other props go to the rendered element, so className, style and event handlers work as usual.
Web and React Native
Each item gets a wrapper element (li inside ul or ol, otherwise div; itemAs changes it) styled with itemClassName.
Keys must be unique. Wrap the list in MotionHeight to animate its total height as well.
Used in these examples
- Chat answerSuggestions that fold away, an answer that streams at a steady pace and a status line that swaps.
MotionStreamMotionListMotionSwapMotionHeight - Checkout summaryQuantities, line totals and the total roll as the cart changes; the coupon notice enters and leaves; paying takes a deliberate hold.
MotionListMotionNumberMotionPresenceMotionHold - InboxFilter tabs with live counts, rows you can swipe away and a list that closes the gap.
MotionHighlightMotionListMotionSwipeMotionNumber