This is rather important functionality, and every library has it.
With gsap I am quite clueless on how to achieve this. It may be more of a question about React though, but since it is the defacto FE framework, I think it is important to provide a sanctioned way of doing this.
I am talking about the situation where you set up a context with an animation, say a sidebar. Then by clicking a button you toggle it, which plays the animation but when you close it, since the state is controlled by a variable, it immediately disappears, which is expected but not wanted behavior.
Framer motion solves this situation by providing a AnimatePresence with exitBeforeEnter attribute.
I have read the docs and especially the three articles regarding React a few times, but failed to see where you solve this super common situation.
Regards