Skip to content

Commit ca8b527

Browse files
committed
fixes
1 parent 4e4c4b1 commit ca8b527

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

images/p5/page.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
'use client';
2+
3+
import { useEffect } from 'react';
4+
15
export default function Home() {
2-
return <></>;
6+
useEffect(() => {
7+
// Only run p5 initialization on the client side
8+
if (typeof window !== 'undefined') {
9+
new window.p5();
10+
}
11+
12+
// Cleanup function
13+
return () => {
14+
if (typeof window !== 'undefined' && window.p5) {
15+
// Remove the canvas when component unmounts
16+
document.querySelector('canvas')?.remove();
17+
}
18+
};
19+
}, []); // Empty dependency array means this runs once on mount
20+
21+
return <main>{/* p5.js will create and inject the canvas here */}</main>;
322
}

0 commit comments

Comments
 (0)