Skip to content

Instantly share code, notes, and snippets.

@AvasDream
Created December 14, 2022 11:25
Show Gist options
  • Save AvasDream/6a8c90b9d0478a97407203484521cc1a to your computer and use it in GitHub Desktop.
Save AvasDream/6a8c90b9d0478a97407203484521cc1a to your computer and use it in GitHub Desktop.
React Confetti in Nextjs
import { Box, Center, Text } from "@chakra-ui/react";
import { useEffect, useState } from "react";
import ApplicationForm from "../components/application/ApplicationForm";
import Confetti from "react-confetti";

export default function Application() {
  const [dimensions, setDimensions] = useState({
    width: 0,
    height: 0,
  });
  const [isClient, setClient] = useState(false);
  useEffect(() => {
    const { innerWidth: width, innerHeight: height } = window;
    setDimensions({
      width,
      height,
    });
    setClient(true);
  }, []);

  return (
    <>
      <Center>
        {isClient && (
          <Confetti width={dimensions.width} height={dimensions.height} />
        )}
        <Box
          h="87vh"
          w="100vh"
          display="flex"
          alignItems={"center"}
          justifyContent={"center"}
        >
          <Text>Hello World</Text>
        </Box>
      </Center>
    </>
  );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment