⚠️ This lesson is retired and might contain outdated information.

Animate your user interface in React with styled-components and "keyframes"

Share this video with your friends

Social Share Links

Send Tweet

In this lesson, we learn how to handle CSS keyframe animations in styled-components, via the 'keyframes' helper.

[00:00] Here is a react app that is a simple bowl component, which is just a DIV with some styles applied to it. Here are some CSS keyframes animations that animate the rotate and border-radius properties. To use keyframe animations in style components, we'll import the keyframes named exports. I'll create the const moff and right keyframes followed by bactics.

[00:23] In here, I'll paste the declaration of the moff animation. Let's do the same one more time, const spin equals keyframes, and we'll paste the CSS in there, too. In the bowl component here, which is a style component, I can now access these keyframes.

[00:40] Animation, dollar sign curly braces, moff -- which is the name of the constant here -- and we give it a duration of one second, a linear easing, and make it loop for ever. Let's save and check it out.

[00:54] Here we go. The bowl now looks like its breathing in and out. Let's take it for spin by chaining the other keyframes animation. Spin, one second as well. This time ease in, out, and infinite again. That's how you handle keyframe animation in style components.