We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4e4c4b1 commit ca8b527Copy full SHA for ca8b527
images/p5/page.js
@@ -1,3 +1,22 @@
1
+'use client';
2
+
3
+import { useEffect } from 'react';
4
5
export default function Home() {
- 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>;
22
}
0 commit comments