Motion (`motion/react`) in Core
API usage for motion/react. Core's motion contract (tokens, presets, route view transitions, reduced-motion baseline) lives in docs/ai/skills/anim/SKILL.md; read it first.
Rules
- Import path: ESLint bans direct
motion/reactandframer-motionimports. Import from@asym/lib/motion, whosemotionexport is the lazymcomponent; the rootMotionProvider(@asym/lib/motion-provider) suppliesLazyMotionandMotionConfig reducedMotion="user"in every app. - Client-only boundary: Motion requires
'use client'; keep client islands small. - Start simple: Begin with opacity/translate before adding spring physics.
- Use the right tool:
AnimatePresencefor enter/exit andwhileHover/whileTapfor gestures. - No layout or drag features:
MotionProviderloadsdomAnimation, which excludes thelayoutanddragfeatures (they are indomMax). Alayoutordragprop does nothing under it. Animateopacity/transforminstead; loadingdomMaxis a deliberate bundle decision for the shared provider, not a per-component fix. - Respect reduced motion:
MotionConfigalready disables transform and layout animation for reduced-motion users; useuseReducedMotion()when the component needs a different fallback. - Shared timing: Use
@asym/lib/motion-presetsconstants and transitions instead of literal durations and curves.
Workflow
- Identify the UX purpose (feedback, transition, focus).
- Add the smallest
'use client'boundary. - Implement enter/exit or layout transitions correctly.
- Respect reduced motion preferences.
- Check performance and bundle size.
Checklists
Implementation checklist
- [ ]
'use client'only where needed - [ ] Reduced motion behavior defined
- [ ]
AnimatePresencewraps conditional UI - [ ] No reliance on
layoutordragprops (not loaded bydomAnimation)
Review checklist
- [ ] Animations don’t re-run on every render
- [ ] Motion code doesn’t expand the client tree unnecessarily
Minimal examples
Enter/exit
"use client";
import { AnimatePresence, motion } from "@asym/lib/motion";
import { transitionStandard } from "@asym/lib/motion-presets";
export function Toast({
open,
children,
}: {
open: boolean;
children: React.ReactNode;
}) {
return (
<AnimatePresence>
{open ? (
<motion.div
initial={{ opacity: 0, y: 8 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: 8 }}
transition={transitionStandard}
>
{children}
</motion.div>
) : null}
</AnimatePresence>
);
}
Reduced motion
"use client";
import { motion, useReducedMotion } from "@asym/lib/motion";
import { transitionStandard } from "@asym/lib/motion-presets";
export function FadeIn({ children }: { children: React.ReactNode }) {
const reduce = useReducedMotion();
return (
<motion.div
initial={reduce ? false : { opacity: 0, y: 6 }}
animate={reduce ? { opacity: 1 } : { opacity: 1, y: 0 }}
transition={transitionStandard}
>
{children}
</motion.div>
);
}
Common mistakes / pitfalls
- Unmounting without
AnimatePresence(exit animations never run) - Expecting
layoutordragto animate under the shareddomAnimationprovider - Putting Motion in a huge client tree
- Importing from
motion/reactdirectly or adding anotherLazyMotionprovider - Animating large lists without virtualization