LoginSignup
10
6

More than 3 years have passed since last update.

react-confettiで紙吹雪を舞わせる

Posted at

はじめに

Vercelでデプロイしたら紙吹雪が舞い、高まったので実装しらべました。
お祝いする/されるのは喜ばしいものですね :confetti_ball:

image.png

今回使うのはreact-confettiというライブラリです。

公開されているデモ

https://alampros.github.io/react-confetti/?path=/story/props-demos--knobs
色んなエフェクトがかけられそうですね。

実装

まずは react-confetti をインストールします。
ターミナルから下記のコマンドを実行してください。
react-usewidthheight の指定が推奨されているためインストールしています。

必要なパッケージのインストール
$ npm install react-confetti react-use

インストールが終わったら、reactでコンポーネントを記述します。これだけ!

react
import React from "react"
import useWindowSize from 'react-use/lib/useWindowSize'
import Confetti from 'react-confetti'

export default () => {
  const { width, height } = useWindowSize()
  return (
    <>
      <Confetti
        width={width}
        height={height}
        recycle={true}
      />
      <h1>ありがとう</h1>
    </>
  )
}

完成画面

image.png

感想

こんな高まるエフェクトが一瞬で実装できるのは喜ばしいことですね:relaxed:

10
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
6