Skip to content

Commit f4ad56c

Browse files
committed
gradient
1 parent 887c541 commit f4ad56c

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

packages/ui/src/gradient-preview/PastelGradientCanvas.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ export const PastelGradientCanvas = ({
99
width?: number;
1010
height?: number;
1111
}) => {
12-
const canvasRef = useRef(null);
12+
const canvasRef = useRef<HTMLCanvasElement | null>(null);
1313

1414
useEffect(() => {
15+
if (!canvasRef.current) return;
1516
const canvas = canvasRef.current;
1617
const ctx = canvas.getContext("2d");
17-
let animationFrameId;
18+
let animationFrameId: number;
1819

1920
const resizeCanvas = () => {
2021
canvas.width = window.innerWidth;
@@ -30,6 +31,11 @@ export const PastelGradientCanvas = ({
3031
const w = canvas.width;
3132
const h = canvas.height;
3233

34+
if (!ctx) {
35+
animationFrameId = requestAnimationFrame(animate);
36+
return;
37+
}
38+
3339
ctx.clearRect(0, 0, w, h);
3440

3541
// Base fill for a light pastel foundation

0 commit comments

Comments
 (0)