Exploring this fiddle, I encountered a small div
showcasing an opacity animation.
The animation smoothly executes when the state transitions to true
upon mounting the component,
causing the div
to fade in beautifully.
However, I faced a challenge as the animation fails to trigger when the component is unmounted and the state changes to false
.
Even after trying different approaches like setting the animation as both
and attempting a reverse animation (from 1 to 0), it only ends up playing immediately following the initial one, resulting in the disappearance of the square.
Is there a way to ensure that this fade animation plays in reverse when the component disappears?
Edit: I omitted mentioning that this scenario is within React environment. Eventually, my workaround involved incorporating an animation library, simplifying the process significantly. Nonetheless, I am keeping this question posted in case others might have vanilla solutions to this issue.