Overview
TheuseWillChange() hook returns a WillChange motion value that automatically manages the CSS will-change property. This helps browsers optimize rendering performance for animated elements.
Import
Usage
Return Value
A special
MotionValue that extends the standard MotionValue<string> interface with an add() method.WillChange Interface
How It Works
TheuseWillChange() hook automatically manages the will-change CSS property:
- When animating transform or accelerated properties, it sets
will-change: transform - When animations complete, it resets to
will-change: auto - This hints to the browser which properties will animate, enabling GPU acceleration
Examples
Basic Usage
Automaticwill-change management:
With Complex Animations
Optimize complex animation sequences:Multiple Animated Elements
Each element gets its ownwill-change management:
Manual Control
Manually add properties towill-change:
Performance Benefits
The
will-change property hints to the browser that an element will animate, allowing it to prepare optimizations in advance. This is especially beneficial for transform and opacity animations.Optimized Properties
The following properties triggerwill-change: transform:
- Transform properties:
x,y,z,scale,rotate,skew, etc. - Accelerated values:
opacity
When to Use
Interactive elements
Interactive elements
Use
useWillChange() on elements with hover, tap, or drag animations that users interact with frequently.Layout animations
Layout animations
Apply to elements that use layout animations or shared layout transitions for smoother performance.
Scroll-triggered animations
Scroll-triggered animations
Use on elements with scroll-triggered animations that change transform or opacity.
Avoid overuse
Avoid overuse
Don’t apply to every element. The
will-change property consumes memory, so use it selectively on elements that actually animate.API Details
add() Method
Manually add a property to track forwill-change:
The name of the property to track (e.g., “x”, “opacity”, “scale”)
- Only transform and accelerated properties trigger
will-change: transform - Other properties are ignored
- Once any tracked property is added, sets
will-change: transform - When no tracked properties remain, resets to
will-change: auto
Browser Support
Implementation Details
- Extends
MotionValue<string>class - Initializes with value
"auto" - Tracks whether any accelerated properties are being animated
- Automatically updates the value between
"transform"and"auto" - Lightweight and designed for reuse across multiple elements
Related
useMotionValue
Create motion values
Performance Guide
Optimize animations
MotionValue
MotionValue API reference