@@ -113,7 +113,6 @@ const App = () => {
113113 enable: true ,
114114 mode: " repulse" ,
115115 },
116- resize: true ,
117116 },
118117 modes: {
119118 push: {
@@ -149,7 +148,6 @@ const App = () => {
149148 number: {
150149 density: {
151150 enable: true ,
152- area: 800 ,
153151 },
154152 value: 80 ,
155153 },
@@ -187,118 +185,116 @@ const App = () => {
187185``` tsx
188186import { useEffect , useMemo , useState } from " react" ;
189187import Particles , { initParticlesEngine } from " @tsparticles/react" ;
190- import type { Container } from " @tsparticles/engine" ;
188+ import { type Container , type ISourceOptions , MoveDirection , OutMode } from " @tsparticles/engine" ;
191189// import { loadAll } from "@/tsparticles/all"; // if you are going to use `loadAll`, install the "@tsparticles/all" package too.
192190// import { loadFull } from "tsparticles"; // if you are going to use `loadFull`, install the "tsparticles" package too.
193191import { loadSlim } from " @tsparticles/slim" ; // if you are going to use `loadSlim`, install the "@tsparticles/slim" package too.
194192// import { loadBasic } from "@tsparticles/basic"; // if you are going to use `loadBasic`, install the "@tsparticles/basic" package too.
195193
196194const App = () => {
197- const [init, setInit] = useState (false );
198-
199- // this should be run only once per application lifetime
200- useEffect (() => {
201- initParticlesEngine (async (engine ) => {
202- // you can initiate the tsParticles instance (engine) here, adding custom shapes or presets
203- // this loads the tsparticles package bundle, it's the easiest method for getting everything ready
204- // starting from v2 you can add only the features you need reducing the bundle size
205- // await loadAll(engine);
206- // await loadFull(engine);
207- await loadSlim (engine );
208- // await loadBasic(engine);
209- }).then (() => {
210- setInit (true );
211- });
212- }, []);
213-
214- const particlesLoaded = (container : Container ) => {
215- console .log (container );
216- };
217-
218- const options = useMemo (
219- () => ({
220- background: {
221- color: {
222- value: " #0d47a1" ,
223- },
224- },
225- fpsLimit: 120 ,
226- interactivity: {
227- events: {
228- onClick: {
229- enable: true ,
230- mode: " push" ,
231- },
232- onHover: {
233- enable: true ,
234- mode: " repulse" ,
235- },
236- resize: true ,
237- },
238- modes: {
239- push: {
240- quantity: 4 ,
241- },
242- repulse: {
243- distance: 200 ,
244- duration: 0.4 ,
245- },
246- },
247- },
248- particles: {
249- color: {
250- value: " #ffffff" ,
251- },
252- links: {
253- color: " #ffffff" ,
254- distance: 150 ,
255- enable: true ,
256- opacity: 0.5 ,
257- width: 1 ,
258- },
259- move: {
260- direction: " none" ,
261- enable: true ,
262- outModes: {
263- default: " bounce" ,
264- },
265- random: false ,
266- speed: 6 ,
267- straight: false ,
268- },
269- number: {
270- density: {
271- enable: true ,
272- area: 800 ,
273- },
274- value: 80 ,
275- },
276- opacity: {
277- value: 0.5 ,
278- },
279- shape: {
280- type: " circle" ,
281- },
282- size: {
283- value: { min: 1 , max: 5 },
284- },
285- },
286- detectRetina: true ,
287- }),
288- []
289- );
290-
291- if (init ) {
292- return (
293- <Particles
294- id = " tsparticles"
295- particlesLoaded = { particlesLoaded }
296- options = { options }
297- />
195+ const [ init, setInit ] = useState (false );
196+
197+ // this should be run only once per application lifetime
198+ useEffect (() => {
199+ initParticlesEngine (async (engine ) => {
200+ // you can initiate the tsParticles instance (engine) here, adding custom shapes or presets
201+ // this loads the tsparticles package bundle, it's the easiest method for getting everything ready
202+ // starting from v2 you can add only the features you need reducing the bundle size
203+ // await loadAll(engine);
204+ // await loadFull(engine);
205+ await loadSlim (engine );
206+ // await loadBasic(engine);
207+ }).then (() => {
208+ setInit (true );
209+ });
210+ }, []);
211+
212+ const particlesLoaded = async (container : Container ): Promise <void > => {
213+ console .log (container );
214+ };
215+
216+ const options: ISourceOptions = useMemo (
217+ () => ({
218+ background: {
219+ color: {
220+ value: " #0d47a1" ,
221+ },
222+ },
223+ fpsLimit: 120 ,
224+ interactivity: {
225+ events: {
226+ onClick: {
227+ enable: true ,
228+ mode: " push" ,
229+ },
230+ onHover: {
231+ enable: true ,
232+ mode: " repulse" ,
233+ },
234+ },
235+ modes: {
236+ push: {
237+ quantity: 4 ,
238+ },
239+ repulse: {
240+ distance: 200 ,
241+ duration: 0.4 ,
242+ },
243+ },
244+ },
245+ particles: {
246+ color: {
247+ value: " #ffffff" ,
248+ },
249+ links: {
250+ color: " #ffffff" ,
251+ distance: 150 ,
252+ enable: true ,
253+ opacity: 0.5 ,
254+ width: 1 ,
255+ },
256+ move: {
257+ direction: MoveDirection .none ,
258+ enable: true ,
259+ outModes: {
260+ default: OutMode .out ,
261+ },
262+ random: false ,
263+ speed: 6 ,
264+ straight: false ,
265+ },
266+ number: {
267+ density: {
268+ enable: true ,
269+ },
270+ value: 80 ,
271+ },
272+ opacity: {
273+ value: 0.5 ,
274+ },
275+ shape: {
276+ type: " circle" ,
277+ },
278+ size: {
279+ value: { min: 1 , max: 5 },
280+ },
281+ },
282+ detectRetina: true ,
283+ }),
284+ []
298285 );
299- }
300286
301- return <></>;
287+ if (init ) {
288+ return (
289+ <Particles
290+ id = " tsparticles"
291+ particlesLoaded = { particlesLoaded }
292+ options = { options }
293+ />
294+ );
295+ }
296+
297+ return <></>;
302298};
303299```
304300
0 commit comments