• AnimatePresence enables the animation of components that have been removed from the tree.

    When adding/removing more than a single child, every child must be given a unique key prop.

    Any motion components that have an exit property defined will animate out when removed from the tree.

    import { motion, AnimatePresence } from 'framer-motion'

    export const Items = ({ items }) => (
    <AnimatePresence>
    {items.map(item => (
    <motion.div
    key={item.id}
    initial={{ opacity: 0 }}
    animate={{ opacity: 1 }}
    exit={{ opacity: 0 }}
    />
    ))}
    </AnimatePresence>
    )

    You can sequence exit animations throughout a tree using variants.

    If a child contains multiple motion components with exit props, it will only unmount the child once all motion components have finished animating out. Likewise, any components using usePresence all need to call safeToRemove.

    Parameters

    Returns ReactNode

Properties

contextTypes?: ValidationMap<any>

Deprecated

Lets you specify which legacy context is consumed by this component.

See

Legacy React Docs

defaultProps?: Partial<PropsWithChildren<AnimatePresenceProps>>

Used to define default values for the props accepted by the component.

See

React Docs

Example

type Props = { name?: string }

const MyComponent: FC<Props> = (props) => {
return <div>{props.name}</div>
}

MyComponent.defaultProps = {
name: 'John Doe'
}
displayName?: string

Used in debugging messages. You might want to set it explicitly if you want to display a different name for debugging purposes.

See

Legacy React Docs

Example


const MyComponent: FC = () => {
return <div>Hello!</div>
}

MyComponent.displayName = 'MyAwesomeComponent'
propTypes?: WeakValidationMap<PropsWithChildren<AnimatePresenceProps>>

Used to declare the types of the props accepted by the component. These types will be checked during rendering and in development only.

We recommend using TypeScript instead of checking prop types at runtime.

Generated using TypeDoc