"use client" import { useEffect, useRef, useState } from "react" import Snowfall from "react-snowfall" import { useStore } from "@/app/store" export function Background() { const panel = useStore(state => state.panel) const [itsRainingFaces, makeItRain] = useState(false) const [nbFaces, setNbFaces] = useState(0) const nbFacesRef = useRef(0) const [sprite, setSprite] = useState() useEffect(() => { const newSprite = document.createElement('img') newSprite.src = "/images/sprite.png" // '/images/hf.png' setSprite(newSprite) }, []) // just to delay things a bit useEffect(() => { setTimeout(() => { makeItRain(true) }, 1000) }, []) // effect is more interesting if progressive useEffect(() => { let interval = setInterval(() => { // if (!itsRainingFaces) { return } if (nbFacesRef.current > 25) { clearInterval(interval) } else { setNbFaces(nbFacesRef.current += 1) } }, 1000) }, []) return ( <>{itsRainingFaces && sprite ? : null} ) }