react-confetti icon indicating copy to clipboard operation
react-confetti copied to clipboard

Not taking full width and height

Open mahautlatinis opened this issue 2 years ago • 12 comments

Hello, sorry I am a noob. I am trying to generate confettis on a page where there is a canva. I am sending the height and width of the window but the confettis are not taking the full page. Do you have an issue of the issue ?

mahautlatinis avatar May 02 '22 16:05 mahautlatinis

I would need more information to help with this. Can you provide a repro sandbox?

alampros avatar May 04 '22 17:05 alampros

Im experiencing the same issue. When i resize the window, it goes to full width and height, but on first load the confetti just takes up a small column:

image

tmwlsh avatar May 25 '22 09:05 tmwlsh

same here

alieldeba avatar Jul 13 '22 06:07 alieldeba

The initial value of the canvas width and height are getting set to "Infinity" and not changing until a resize. Setting a state to show the confetti once the page loads seems to work fine for me.

import React, { useEffect, useState } from 'react'
import { useWindowSize } from 'react-use'
import Confetti from 'react-confetti'

const Index = () => {
	const [LOADED, setLoaded] = useState(false)

	const { width, height } = useWindowSize()

	useEffect(() => {
		setLoaded(true)
	}, [])

	return LOADED && <Confetti width={width} height={height} />
}

export default Index

NahanaBanahnah avatar Jul 26 '22 13:07 NahanaBanahnah

Hello, sorry I am a noob. I am trying to generate confettis on a page where there is a canva. I am sending the height and width of the window but the confettis are not taking the full page. Do you have an issue of the issue ?

After I rendered my Confetti component I just gave it a className. In CSS I then set the height and width to 100%. It now responds to my browser changes.

Hgray1109 avatar Aug 24 '22 14:08 Hgray1109

Yo can use something like this:

<Confetti
    width={window.innerWidth}
    height={window.innerHeight}
/>

mmartindj avatar Aug 25 '22 10:08 mmartindj

same here

popQA17 avatar Aug 31 '22 14:08 popQA17

I'm getting this with next.js. I don't think this lib works properly with ssr.

hichemfantar avatar Oct 03 '22 12:10 hichemfantar

if u guys using next-js use dynamic import

const Confetti = dynamic(() => import('react-confetti'), {
  ssr: false,
})

It's solved my problem

asaadam avatar Oct 31 '22 12:10 asaadam

Thanks @asaadam Dynamic Import solved my issue too!

Praneeth-Pike avatar Nov 01 '22 11:11 Praneeth-Pike

Hi, i am adding a confetti mid section not at the top, and i have added state to run confetti when div is reached. My state is working, when i reach the div the confetti appears but it doesnt appear on the div. it appears on the top of my screen.

How do i fix this?

karimdakroury avatar Feb 02 '23 07:02 karimdakroury

For anyone having trouble with the confetti component not being as large as you hoped, add some console logging of the values that you get from const { width, height } = useWindowSize().

That's how I figured out that my confetti component wasn't even seeing the values that I expected.

ryancwalsh avatar Sep 14 '23 23:09 ryancwalsh