[ TIL 221204 ] react-spring

ponyo·2022년 12월 3일
0

Today I Learned

목록 보기
13/30

react-spring

bring your componenets to life with simple spring animation primitives

Installation

yarn add react-spring

function Text() {
  const [flip, set] = useState(false)
  const props = useSpring({
    to: { opacity: 1 },
    from: { opacity: 0 },
    reset: true,
    reverse: flip,
    delay: 200,
    config: config.molasses,
    onRest: () => set(!flip),
  })

  return <animated.h1 style={props}>hello</animated.h1>
}

function Number() {
  const [flip, set] = useState(false)
  const { number } = useSpring({
    reset: true,
    reverse: flip,
    from: { number: 0 },
    number: 1,
    delay: 200,
    config: config.molasses,
    onRest: () => set(!flip),
  })

  return <animated.div>{number.to(n => n.toFixed(2))}</animated.div>
}

앞으로 프로젝트 진행하면서 react-spring를 사용하게되면 게시글을 업데이트 하자!! 🚀

profile
😁

0개의 댓글