Skip to content

Commit 4ef5e81

Browse files
committed
fix: fixed component, it was refreshing infinite times for a bug. now it works perfectly
1 parent d15e5ca commit 4ef5e81

File tree

13 files changed

+711
-922
lines changed

13 files changed

+711
-922
lines changed

apps/nextjs-beta/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
},
1212
"dependencies": {
1313
"@next/font": "^14.0.3",
14-
"@tsparticles/configs": "^3.0.0",
15-
"@tsparticles/engine": "^3.0.0",
14+
"@tsparticles/configs": "^3.0.2",
15+
"@tsparticles/engine": "^3.0.2",
1616
"@tsparticles/react": "workspace:^",
17-
"@types/node": "^20.10.3",
17+
"@types/node": "^20.10.4",
1818
"@types/react": "^18.2.42",
1919
"@types/react-dom": "^18.2.17",
2020
"eslint": "^8.55.0",
2121
"eslint-config-next": "^14.0.3",
2222
"next": "^14.0.3",
2323
"react": "^18.2.0",
2424
"react-dom": "^18.2.0",
25-
"tsparticles": "^3.0.0-beta.4",
26-
"typescript": "^5.3.2"
25+
"tsparticles": "^3.0.2",
26+
"typescript": "^5.3.3"
2727
}
2828
}

apps/nextjs/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
"lint": "next lint"
1111
},
1212
"dependencies": {
13-
"@tsparticles/engine": "^3.0.0",
13+
"@tsparticles/engine": "^3.0.2",
1414
"@tsparticles/react": "workspace:^",
1515
"@tsparticles/preset-big-circles": "^3.0.0",
1616
"next": "^14.0.3",
1717
"react": "^18.2.0",
1818
"react-dom": "^18.2.0",
19-
"typescript": "^5.3.2"
19+
"typescript": "^5.3.3"
2020
},
2121
"devDependencies": {
2222
"eslint": "^8.55.0",

apps/react/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
"version": "3.0.0-beta.1",
44
"private": true,
55
"dependencies": {
6-
"@tsparticles/engine": "^3.0.0",
6+
"@tsparticles/engine": "^3.0.2",
77
"@tsparticles/react": "workspace:^",
88
"react": "^18.2.0",
99
"react-dom": "^18.2.0",
1010
"react-scripts": "^5.0.1",
11-
"tsparticles": "^3.0.0",
11+
"tsparticles": "^3.0.2",
1212
"web-vitals": "^3.5.0"
1313
},
1414
"scripts": {

apps/react/src/App.js

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ import logo from "./logo.svg";
55
import "./App.css";
66

77
function App() {
8-
const containerRef = useRef(null),
9-
initParticlesCb = useCallback(async (engine) => {
10-
await loadFull(engine);
11-
}, []), [ init, setInit ] = useState(false);
8+
const containerRef = useRef(null), [ init, setInit ] = useState(false);
129

1310
useEffect(() => {
14-
initParticlesEngine(initParticlesCb).then(() => {
11+
if (init) {
12+
return;
13+
}
14+
15+
initParticlesEngine(async (engine) => {
16+
await loadFull(engine);
17+
}).then(() => {
1518
setInit(true);
1619
});
17-
}, [ initParticlesCb ]);
20+
}, [ init ]);
1821

1922
const particlesLoaded = useCallback(
2023
(container) => {
@@ -87,28 +90,12 @@ function App() {
8790
}),
8891
[]
8992
),
90-
lightTheme = useCallback(() => {
91-
if (!containerRef.current) {
92-
return;
93-
}
94-
95-
console.log(containerRef.current);
96-
97-
setTimeout(() => {
98-
containerRef.current.loadTheme("light");
99-
}, 500);
100-
}, [ containerRef ]),
101-
darkTheme = useCallback(() => {
102-
if (!containerRef.current) {
103-
return;
104-
}
105-
106-
console.log(containerRef.current);
107-
108-
setTimeout(() => {
109-
containerRef.current.loadTheme("dark");
110-
}, 500);
111-
}, [ containerRef ]);
93+
lightTheme = () => {
94+
containerRef.current?.loadTheme("light");
95+
},
96+
darkTheme = () => {
97+
containerRef.current?.loadTheme("dark");
98+
};
11299

113100
return (
114101
<div className="App">
@@ -135,7 +122,7 @@ function App() {
135122
{init && (
136123
<Particles
137124
id="tsparticles"
138-
loaded={particlesLoaded}
125+
particlesLoaded={particlesLoaded}
139126
options={options}
140127
/>
141128
)}

0 commit comments

Comments
 (0)