Replies: 2 comments 2 replies
-
I've checked the CodeSandbox, and I noticed an issue immediately:
This is better if it's moved in the App.tsx file or something like that, these plugins must be loaded only once per application. The rest seems fine, maybe this issue could have unexpected behavior since every plugin could reload the instance. |
Beta Was this translation helpful? Give feedback.
-
Yep, making sure to only load the engine once is the key. Thank you @matteobruni for your insight and for this really cool library. I'm looking forward to applying it to more use cases! For anyone else that found their way here, this is how I handled it. You can also visit the CodeSandbox link I posted above. const nextConfig = {
reactStrictMode: false,
// other configs...
}; I created a This approach allows the engine to load in the background. If there's a The new challenge I have is figuring out how to display a play or pause button depending on an |
Beta Was this translation helpful? Give feedback.
-
Hello, I'm wondering if there's a way to control the particles animation state in a react environment. I'm using
tsparticles v3.3.0
and@tsparticles/react v3.0.0
. I have two buttons that each have anonClick
handler that is responsible or either playing or pausing the particles animation.I want to achieve the same play/pause button functionality that the particles.js.org config editor achieves. My buttons work sometimes, but the results are very inconsistent. More often than not, the handlers are either ignored or produce weird side-effects.
I've tried looking for solutions all over the
tsparticles
umbrella. The closest solution I found was Issue #4697. The problem with this (and other related) solutions is that they are either out of date or aren't using an official framework component (such as Issue #5231). Thev3.0.0
components don't have access to the same props, such as theparticlesInit
prop, though I'm not sure how much this really matters.I have created a CodeSandbox example that goes into more detail. See the README and the content on the rendered home page. This isn't really a minimal sandbox, but it emulates my exact environment. The only file that matters is the
<HexagonParticles />
component found in'./components/HexagonParticles.tsx'
. It is setup nearly exactly as the example react app located in this package.I'm not sure if other frameworks have a hard time with this functionality. It could be a react thing due to how re-rendering works, and that I simply lack the knowledge on how to overcome this.
Any help or insight is much appreciated.
Beta Was this translation helpful? Give feedback.
All reactions