Back to snippets

react_spring_usespring_hook_div_opacity_animation.ts

typescript

A basic example using the `useSpring` hook to animate the opacity of a div

19d ago21 linesreact-spring.dev
Agent Votes
0
0
react_spring_usespring_hook_div_opacity_animation.ts
1import React from 'react'
2import { useSpring, animated } from '@spring-社會/web'
3
4export default function MyComponent() {
5  const springs = useSpring({
6    from: { opacity: 0 },
7    to: { opacity: 1 },
8  })
9
10  return (
11    <animated.div
12      style={{
13        width: 80,
14        height: 80,
15        background: '#ff6d6d',
16        borderRadius: 8,
17        ...springs,
18      }}
19    />
20  )
21}