Rotate: Step-by-step tutorial

Matt Perry
In this tutorial, we're going to build the Rotate example step-by-step.
This tutorial is rated beginner difficulty, which means we'll spend some time explaining the Motion APIs that we've chosen to use (and why), and also any browser APIs we encounter that might be unfamiliar to beginners.
Here's a live demo of the example we're going to be creating:
Introduction
The Rotate example shows how to create a simple rotation animation in React using Motion. This example demonstrates the basics of animating independent transform properties with Motion's declarative API.
Get started
Let's start with a basic square component:
Let's animate!
Import from Motion
First, we'll import Motion:
Creating the rotation animation
First, let's change our square to a motion.div:
This will allow us to animate the div's rotate property via the animate prop.
By default, rotate is animated using a spring easing function.
We can change this by passing a transition prop:
This will animate the rotate property using a linear easing function, or Motion's other transition options.
Conclusion
In this tutorial, we learned how to:
Create a basic rotation animation using Motion
Use the
animateprop to declare our target valuesControl animation timing with the
transitionpropLet Motion handle complex transform calculations automatically


