Closed joelhoelting closed 3 years ago
You can try to play/pause instead of conditional rendering if you want.
The container
property described in the readme was added for using those methods.
Anyway I’ll try to reproduce the issue to find a solution in this case
@matteobruni Thank you for the response, I am trying to access the particlesRef
within React hooks in order to utilize the container functions. Is there an example of how to do this? I will be happy to PR to the docs with an example once I figure it out.
You can find some code from the author of the PR that added that property here:
He uses that property in a button, probably it's something useful for you too
@matteobruni Re: the conditional rendering of the particles container: this.options is undefined
only occurs in the browser sometimes. It does not happen every time. It happens like every 1/5 times, perhaps it is because this.options
is being called before the particles component has fully rendered?
I have reached out to @crutchcorn re: accessing the particlesRef
inside of a useEffect hook. I am still struggling to implement particlesRef
(see below) but once I figure it out I will definitely submit a PR to the docs to provide an example for others on how to achieve this.
Here is my failed implementation that I put together after looking at the code written by @crunchcorn posted above:
File in question (Line 115): https://github.com/joelhoelting/joel-hoelting-personal-site/blob/develop/src/components/pages/home/landing/index.js
particlesRef.current is undefined
First: I really like what you're doing with the website @joelhoelting!
Secondly: I've double-checked your project, and I believe it's due to an outdated version of react-particles-js
is installed. I updated the package to 3.2.1
and the console.log
now works perfectly.
@crutchcorn Wow, that's a little embarrassing...
Thanks for taking a look at my code, the good work and the compliment! I can access the container object now.
Glad to hear! Don't sweat it, we all make those mistakes from time-to-time. I think I've even done that for this project in particular 😄
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I noticed that the CPU load is pretty high when the particles are rendering. In order to give the user a more lightweight experience I decided to conditionally render the particles only when the particle div is visible. I am getting an error within the
react-particles-js
library during conditional rendering:TypeError: this.options is undefined
Here is some sample code:
Github repo source: Github Repo
The issue is coming from the
tsparticles
library and I've isolated the error toreact-particles-js/node_modules/tsparticles/dist/Core/Container.js
.I am trying to figure out the root of the issue. In the meantime, does anyone know why this is occurring or a know of a better way to conditionally render a particle component in react?