useValue
The useValue hook is the core of React UI Animate. It creates animated values that update smoothly without causing React re-renders, making your animations performant and your code simple.
Understanding useValue
Think of useValue as useState optimized for animations. It returns a tuple [value, setValue] that you can use just like useState, but with superpowers:
- ✅ No re-renders - Updates happen outside React's render cycle
- ✅ Smooth animations - Works seamlessly with animation modifiers
- ✅ Flexible types - Supports numbers, strings, arrays, and objects
- ✅ Direct style binding - Use values directly in JSX styles
Basic Usage
The simplest way to use useValue is with a number:
import { useValue, animate } from 'react-ui-animate';
function MyComponent() {
const [width, setWidth] = useValue(100);
return (
<animate.div style={{ width, height: 100, background: 'teal' }} />
);
}