Hi I am working with Gsap on React and I need to destroy elements after my animation is complete.
I am using a state and conditional rendering and it works fine if animate a parent element and destroy its children, but in other cases I need to destroy the element I am animating, but I get an infinite error saying "Cannot tween a null target".
Do you guys have an idea or a better approach to destroying elements after animating them? Please note that I will need them back later.
My code looks something like this:
TweenLite.to(this.paths, 0.3, {
opacity: 0,
onComplete: this.destroyIntro,
});
destroyIntro = () => {
this.setState({ destroyIntro: true });
};
{!destroyIntro && (
<div ref={div => this.paths = div}>Content Here</div>
)}