tengbao/vanta

Vanta effect will not destroy. Why?

justsomeusername2020 opened this issue · 2 comments

In my web page project, I want to add an option to disable the VantaJS dynamic background if desired.

Here's my example code, where I added a button that should be destroying the Vanta effect when clicked:
https://jsfiddle.net/playdohsniffer/un6hx1q5/131/

As you can see, I'm using the example javascript exactly as is provided in the "Cleanup" section of the docs:
https://github.com/tengbao/vanta#cleanup

Why does the Vanta not destroy when the button is clicked? Is this a bug?

Seems like it should work using vanilla Javascript. But the doc example mentions to use React's "componentWillUnmount". Is it required to use React? I'm not familiar with that framework at all...

You cannot call destroy on the constructor itself. You need to save the initialized effect to a new variable, then call destroy on that. See working example: https://jsfiddle.net/40qz2w7u/

Many thanks for correcting me. Glad to see you're back!

For anyone viewing this in the future, here's a properly working example using plain Javascript:
https://jsfiddle.net/playdohsniffer/un6hx1q5/133/