Skip to content

Commit 97cdd5b

Browse files
authored
Merge pull request #4 from stevent-team/fix/observer-null-check
Check that canvas ref is set when resizing
2 parents 9aeb49a + fa021cc commit 97cdd5b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/useConfetti.jsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,16 @@ const useConfetti = ({
8585
const ctxRef = useRef()
8686

8787
const onCanvasResize = useCallback(() => {
88-
const canvas = canvasRef.current
89-
const canvasBB = canvas.getBoundingClientRect()
90-
const { width, height } = canvasBB
91-
const scale = window.devicePixelRatio
92-
canvasBBRef.current = canvasBB
93-
canvas.scale = scale
94-
canvas.width = Math.floor(width * scale)
95-
canvas.height = Math.floor(height * scale)
88+
if (canvasRef.current) {
89+
const canvas = canvasRef.current
90+
const canvasBB = canvas.getBoundingClientRect()
91+
const { width, height } = canvasBB
92+
const scale = window.devicePixelRatio
93+
canvasBBRef.current = canvasBB
94+
canvas.scale = scale
95+
canvas.width = Math.floor(width * scale)
96+
canvas.height = Math.floor(height * scale)
97+
}
9698
}, [])
9799

98100
// Observe for canvas size changes

0 commit comments

Comments
 (0)