Framer Motion Gesture Not Working — Fix whileHover/whileTap
In this fix, you'll learn how to use Framer Motion gestures for interactions. This matters for interactive UI elements, and appears in buttons, cards, and draggable items.
The Problem
The following code demonstrates the typical mistake:
<div whileHover={{ scale: 1.1 }}>Hover me</div>
// No effect — regular div doesn't support gesture props
The Fix
Here is the corrected version:
<motion.div whileHover={{ scale: 1.1 }} whileTap={{ scale: 0.95 }}>
Hover me
</motion.div>
// Scales on hover and tap
Prevention
- Always use motion elements (motion.div, motion.button) for gesture animations.
- Gesture props include: whileHover, whileTap, whileDrag, whileFocus, whileInView.
- Multiple gesture props can be combined on the same element.
- Use transition to customize gesture animation physics.
- For complex gestures, define variants and reference them in gesture props.
Common Mistakes with framer motion gesture
- Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
- Using
headandtailinstead of pattern matching, causing runtime errors on empty lists - Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
These mistakes appear frequently in real-world REACT code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro