facebook / react

The library for web and native user interfaces.
https://react.dev
MIT License
229.16k stars 46.89k forks source link

Callback for lifecycle `componentWillUnmount` #10439

Closed inomdzhon closed 7 years ago

inomdzhon commented 7 years ago

React - good the templating engine, but making animation sometime very horrible.

I use GreenSock animation library for animation, since react animation library like react-motion not impressed me for solve design task.

I haven't problem when I need animation after componentDidMount, unlike animation before componentWillUnmount.

I have to apply the "hack" for last situation, example wrapping my component to TransitionGroup (react-transition-group), it's extends react lifecycle (componentWillLeave([callback])), or another "hack".

And in general what I want to ask.

It's possible to add callback for lifecycle componentWillUnmount?

Or how I can easily animate my components?

Kepro commented 7 years ago

https://medium.com/@joethedave/achieving-ui-animations-with-react-the-right-way-562fa8a91935

inomdzhon commented 7 years ago

@Kepro Thanks. I had read this article long time ago. I prefer JS animation, than CSS animation. For this reason I use and like GSAP library. Anyway, author by article recommend use addons (ReactCSSTransitionGroup), but I would like "native" realisation, I mean lifecycle method.

thysultan commented 7 years ago

It could also work with Promises – if React's componentWillUnmount supported a promise as a return type that would tell it if/when to wait, and resolve unmounting after the promise has resolved, here's a proof of concept in action https://dio.js.org/api.html#animations

jquense commented 7 years ago

Making unmounting controllable by the component is not likely to be an feature in the near future. There are a bunch of reasources and options tho for dealing with this limitation though. react-transition-group v2 has a few lower level components that help manage this (specifically the Transition component) and can used for doing animation with other libraries like greensock