@@ -58,21 +58,22 @@ import Particles from "@tsparticles/react";
5858import { loadSlim } from " @tsparticles/slim" ; // if you are going to use `loadSlim`, install the "@tsparticles/slim" package too.
5959
6060const App = () => {
61- const particlesInit = useCallback (async engine => {
62- console .log (engine);
63- // you can initiate the tsParticles instance (engine) here, adding custom shapes or presets
61+ const initParticlesCb = useCallback (async (engine ) => {
62+ // you can initiate the tsParticles instance (engine) here, adding custom shapes or presets
6463 // this loads the tsparticles package bundle, it's the easiest method for getting everything ready
6564 // starting from v2 you can add only the features you need reducing the bundle size
6665 // await loadFull(engine);
6766 await loadSlim (engine);
6867 }, []);
6968
69+ const { done , error } = useParticlesPlugins (initParticlesCb);
70+
7071 const particlesLoaded = useCallback (async container => {
7172 await console .log (container);
7273 }, []);
7374
7475 return (
75- < Particles id= " tsparticles" url= " http://foo.bar/particles.json" init = {particlesInit} loaded = { particlesLoaded} / >
76+ {done && < Particles id= " tsparticles" url= " http://foo.bar/particles.json" particlesLoaded = { particlesLoaded} / > }
7677 );
7778};
7879```
@@ -87,22 +88,22 @@ import type { Container, Engine } from "@tsparticles/engine";
8788import { loadSlim } from " @tsparticles/slim" ; // if you are going to use `loadSlim`, install the "@tsparticles/slim" package too.
8889
8990const App = () => {
90- const particlesInit = useCallback (async (engine : Engine ) => {
91- console .log (engine );
92-
93- // you can initialize the tsParticles instance (engine) here, adding custom shapes or presets
91+ const initParticlesCb = useCallback (async (engine : Engine ) => {
92+ // you can initiate the tsParticles instance (engine) here, adding custom shapes or presets
9493 // this loads the tsparticles package bundle, it's the easiest method for getting everything ready
9594 // starting from v2 you can add only the features you need reducing the bundle size
9695 // await loadFull(engine);
9796 await loadSlim (engine );
9897 }, []);
9998
100- const particlesLoaded = useCallback (async (container : Container | undefined ) => {
99+ const { done, error } = useParticlesPlugins (initParticlesCb );
100+
101+ const particlesLoaded = useCallback (async (container : Container ) => {
101102 await console .log (container );
102103 }, []);
103104
104105 return (
105- < Particles id = " tsparticles" url = " http://foo.bar/particles.json" init = { particlesInit } loaded = { particlesLoaded } / >
106+ { done && <Particles id = " tsparticles" url = " http://foo.bar/particles.json" particlesLoaded = { particlesLoaded } / > }
106107 );
107108};
108109```
@@ -118,24 +119,24 @@ import Particles from "@tsparticles/react";
118119import { loadSlim } from " @tsparticles/slim" ; // if you are going to use `loadSlim`, install the "@tsparticles/slim" package too.
119120
120121const App = () => {
121- const particlesInit = useCallback (async engine => {
122- console .log (engine);
123- // you can initiate the tsParticles instance (engine) here, adding custom shapes or presets
122+ const initParticlesCb = useCallback (async (engine ) => {
123+ // you can initiate the tsParticles instance (engine) here, adding custom shapes or presets
124124 // this loads the tsparticles package bundle, it's the easiest method for getting everything ready
125125 // starting from v2 you can add only the features you need reducing the bundle size
126126 // await loadFull(engine);
127127 await loadSlim (engine);
128128 }, []);
129129
130+ const { done , error } = useParticlesPlugins (initParticlesCb);
131+
130132 const particlesLoaded = useCallback (async container => {
131133 await console .log (container);
132134 }, []);
133135
134136 return (
135- < Particles
137+ {done && < Particles
136138 id= " tsparticles"
137- init= {particlesInit}
138- loaded= {particlesLoaded}
139+ particlesLoaded= {particlesLoaded}
139140 options= {{
140141 background: {
141142 color: {
@@ -205,7 +206,7 @@ const App = () => {
205206 },
206207 detectRetina: true ,
207208 }}
208- / >
209+ / > }
209210 );
210211};
211212```
@@ -220,24 +221,23 @@ import Particles from "@tsparticles/react";
220221import { loadSlim } from " @tsparticles/slim" ; // if you are going to use `loadSlim`, install the "@tsparticles/slim" package too.
221222
222223const App = () => {
223- const particlesInit = useCallback (async (engine : Engine ) => {
224- console .log (engine );
225-
226- // you can initialize the tsParticles instance (engine) here, adding custom shapes or presets
224+ const initParticlesCb = useCallback (async (engine : Engine ) => {
225+ // you can initiate the tsParticles instance (engine) here, adding custom shapes or presets
227226 // this loads the tsparticles package bundle, it's the easiest method for getting everything ready
228227 // starting from v2 you can add only the features you need reducing the bundle size
229228 // await loadFull(engine);
230229 await loadSlim (engine );
231230 }, []);
232231
232+ const { done, error } = useParticlesPlugins (initParticlesCb );
233+
233234 const particlesLoaded = useCallback (async (container : Container | undefined ) => {
234235 await console .log (container );
235236 }, []);
236237 return (
237- < Particles
238+ { done && <Particles
238239 id = " tsparticles"
239- init = {particlesInit }
240- loaded = {particlesLoaded }
240+ particlesLoaded = {particlesLoaded }
241241 options = {{
242242 background : {
243243 color : {
@@ -307,26 +307,23 @@ const App = () => {
307307 },
308308 detectRetina : true ,
309309 }}
310- / >
310+ />}
311311 );
312312};
313313```
314314
315315### Props
316316
317- | Prop | Type | Definition |
318- | --------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
319- | id | string | The id of the element. |
320- | width | string | The width of the canvas. |
321- | height | string | The height of the canvas. |
322- | options | object | The options of the particles instance. |
323- | url | string | The remote options url, called using an AJAX request |
324- | style | object | The style of the canvas element. |
325- | className | string | The class name of the canvas wrapper. |
326- | canvasClassName | string | the class name of the canvas. |
327- | container | object | The instance of the [ particles container] ( https://particles.js.org/docs/classes/tsParticles_Engine.Core_Container.Container.html ) |
328- | init | function | This function is called after the tsParticles instance initialization, the instance is the parameter and you can load custom presets or shapes here |
329- | loaded | function | This function is called when particles are correctly loaded in canvas, the current container is the parameter and you can customize it here |
317+ | Prop | Type | Definition |
318+ | --------------- | ------ | ---------------------------------------------------- |
319+ | id | string | The id of the element. |
320+ | width | string | The width of the canvas. |
321+ | height | string | The height of the canvas. |
322+ | options | object | The options of the particles instance. |
323+ | url | string | The remote options url, called using an AJAX request |
324+ | style | object | The style of the canvas element. |
325+ | className | string | The class name of the canvas wrapper. |
326+ | canvasClassName | string | the class name of the canvas. |
330327
331328#### particles.json
332329
0 commit comments