Animations before unmounting (and in general)
See original GitHub issue(Context: my pull request for fixing the bootstrap modal example: https://github.com/facebook/react/pull/160).
Animation in componentDidMount works, but doesn’t in componentWillUnmount for obvious reason.
Let’s say I have three divs side by side. When the middle one closes, it does a shrinking animation and disappears, and the one on the right moves left to take its place. Currently it takes a bit of circumventing to make this work (and kills the nice structure and semantic react’s aiming for), and at the end it kind of defeats the purpose of the diff rendering technique.
I was wondering if there’d be a clean way, maybe even a new api, to make this work well.
Issue Analytics
- State:
- Created 10 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
React - animate mount and unmount of a single component
All I want to do is animate the mounting & unmounting of a React component, that's it. Here's what I've tried so far...
Read more >How to animate mount and unmount of a react component ...
In this video we add animations to the mount and unmount events of a react component using the react-spring animation library and hooks, ......
Read more >Mount dismount animation - General Discussion
Have you guys noticed a warping bubble around your character when you mount and dismount now? I can't say I've ever noticed it...
Read more >Animated Page Transitions in Next.js | Let's Build UI
Use Framer Motion to animate route changes in your Next.js project. ... exit animation defined on child motion elements before unmounting.
Read more >Getting Started with React Animations
There is no lifecycle method that communicates when a component is going to be unmounted; There is no way to defer unmounting until...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

As far as “animations on unmounting” goes, I usually just toggle a “shown” or “visible” prop on an owner component instead of unmounting directly, since then you can do the transition first and then finally unmount. But YMMV.
As far as “animations in general” goes, I’ve prepared this example for you: https://github.com/petehunt/react-animations. It’s a pretty performant way to tween your state, interpret touch gestures, and animate in a performant way. Let me know if this is helpful!
This sounds like good news. I definitely think webapps is/should be moving toward animated interactions not just of individual components, but as a coherent unit. What worries me in this situation is how the DOM will be reconciliated and how it’ll affect the rest of the flow.
Take todomvc for example. Ignoring the design of react’s animation API, how would it achieve the followings?
I’m really buying the idea of react, and I think it’s a just natural progression to express HTML, then potentially CSS, and then animation all in javascript. I love the smoothness of CSS animation, but as todomvc showed, these kind of animated elements in normal js/CSS frameworks are still constrained to minimal eye candies such as color transition when applying a checkmark, or the x button growing bigger on hover. They’re very bland and frankly, feel like web-grade apps (as much as I love the web).
To reiterate, I’m just worried that given react’s (albeit extremely clever) diff rendering technique, the framework gets constrained in this aspect of UI. You know what would be a sick API? If we can somehow achieve the above two kind of animated interactions directly on top of the existing todomvc, without altering the structure of the app. Animations will only get ubiquitous if it doesn’t interfere with the actual sketching of the app.