useSpring
Our flagship hook. Applicable to most use-cases. If you want to orchestrate many of these hooks, consider using useSprings.
Usage
Whether you're using a function or not, it's all about passing a config object to the hook.
With a function & deps
import { useSpring, animated } from '@react-spring/web'
function MyComponent() {
const [props, api] = useSpring(
() => ({
from: { opacity: 0 },
to: { opacity: 1 },
}),
[]
)
return <animated.div style={props}>Hello World</animated.div>
}
With a config object
import { useSpring, animated } from '@react-spring/web'
function MyComponent() {
const props = useSpring({
from: { opacity: 0 },
to: { opacity: 1 },
})
return <animated.div style={props}>Hello World</animated.div>
}
Reference
| Prop | Type | Default |
|---|---|---|
from | object | – |
to | object | object[] | function | – |
loop | boolean | object | function | – |
delay | number | function | – |
immediate | boolean | function | – |
reset | boolean | – |
reverse | boolean | – |
pause | boolean | – |
cancel | boolean | string | string[] | function | – |
ref | SpringRef | – |
config | object | function | object |
events | function | – |
Typescript
function useSpring(configuration: ConfigObject): SpringValues
function useSpring(
configurationFn: () => ConfigObject,
deps?: any[]
): [springs: SpringValues, api: SpringRef]
Where ConfigObject is described above
TS Glossary
Examples

Animating AutoAnimating widths with react-spring, use-measure and interpolation - useSpring
- useMeasure
- auto
- width
- interpolation

CardAnimating images on a card with react-spring and use-gesture. - useSpring
- interpolation
- useGesture
- scrolling
- cards

Chaining Transition and a SpringOrchestrating a useTransition and useSpring hook with the useChain hook. - useTransition
- useSpring
- useChain
- SpringRef

CSS GradientsUse interpolations & easings to create the CSS gradients you've been seeing all over the web. - useSpring
- interpolation
- leva
- css
- gradients

CSS KeyframesSimulating CSS keyframes with interpolations - useSpring
- interpolation
- css
- keyframes

Exit Before EnterShowcasing the exitBeforeEnter prop and animated clip-paths to give a wipe effect - useTransition
- useSpring
- exitBeforeEnter
- paths
- SpringRef

Flip CardUsing interpolations & CSS 3D create a flip card effect - css
- 3D
- useSpring
- interpolation

Floating ButtonA small floating button like Facebook's desktop messenger built with radix & stitches - use-gesture
- useSpring
- useSprings
- interpolation
- stitches
- radix-ui

Popup ModalAnimate on intersections with the viewport - useInView
- useSpring
- Windows95
- styled-components

Native SlideA native-esque slider component animated with useSpring and useDrag - useSpring
- useDrag
- native
- interpolation

NoiseCreate noise with just a small image and useSpring - useSpring
- easing
- steps
- interpolation

Rocket decayCreate intertia with the velocity and decay config options combined with interpolation - velocity
- intertia
- decay
- interpolation
- useSpring
- useDrag

Svg FilterAnimating SVG filter nodes to distort a path - useSpring
- svg
- filters
- path

Tree ListAnimated tree styled menu list - useSpring
- useMeasure
- tree
- menu
- list
Can't find what you're looking for? Check out all our examples!