visit
Each particle is an SVG circle that looks like…
Since I was using React, I naturally leaned towards trying out .
This was really frustrating because, not only did the tab crash, but also the DevTools window itself. I tried many approaches to profile my scripts and ended up coming up with an interesting hack. I open the console, and when the time was right, I typed debugger and BOOM! I paused everything. All the animations stopped, the React lifecycle, React Motion, everything! I also made sure I had the Timeline tab open in the DevTools to start recording performance on page refresh. I was able to look at all the metrics and debugged performance of my scripts as well as any cpu/memory leaks.
Using TransitionMotion is great for handling multiple elements animating together and having control over mounting and unmounting of each component. But I wasn’t able to get it working using [email protected]. The way I approached it initially was by making use of defaultStyles as the initial positions of each particle and then set styles as the final transition styles after initially starting from the defaultStyles.
What happened was that the particles would just stay at the final position and never go through the animation phase at all. Almost like the defaultStyles didn’t really do anything.
Solution: After three days of trying various solutions, the one that worked was to use the willLeave prop and performed all the animations by returning the final state in its callback. Effectively, ignoring the defaultStyles property. Here’s the working snippet.
By getting rid of defaultStyles altogether and treating styles as the initial state of the animation, everything worked perfectly. I filed the issue on Github below.
Conclusion
React Motion is awesome and provides really powerful tools for animation, but it still has a few gotchas and documentation to iron out. If you use Docker in your stack, give a try. It’s a fun and interesting sight that gives you intuition on microservice networks.