Animating in React (The Many Ways!)

This text introduces you to the totally different choices for creating animations in React, within the course of we’ll have a look at the professionals, and cons of utilizing every approach, and a few necessary statistics, so you understand when to make use of which ones.

Relying on the complexity of your animation, some strategies can be wonderful as they’re, and others which might be optimized to deal with extra advanced animations.

Listed here are the a number of strategies we’ll talk about on this article.

  1. Straight up CSS
  2. React Transition Group
  3. React Movement
  4. React Spring
  5. Greensock Animation Platform(GSAP)
  6. Framer Movement

Let’s get proper into it!

1. Straight up CSS

When constructing a easy internet animation, this can be a nice choice. Utilizing CSS enhances your website efficiency by requiring solely a small quantity of sources out of your browser and machine’s RAM, giving your app a good really feel when utilizing transitions.

You additionally get some management by utilizing the animation property and its sub-properties corresponding to animation-delay and animation-iteration-count.

CSS is finest when you’ve gotten easy transitions like toggling the states of UI components or doing a fadeIn or fadeOut animation.

Nevertheless, suppose you need to chain greater than three animations in a row. In that case, it is best to use a JavaScript (JS) library as an alternative of CSS as a result of CSS sequencing turns into difficult with delays, and you will find yourself with plenty of recalculations in case you miss the timing.

Now, let’s look into the JS/ React libraries for animation.

2. React Transition Group

React Transition Group presents a simple method to animations and transitions by offering its in-built parts corresponding to TransitionGroup for outlining animations.

It additionally exposes transition levels, manages lessons, grouping components, and manipulates the DOM in helpful methods making animating very handy.

One other thrilling characteristic is that it is comparatively small and will not add to the scale of your bundle, and you too can use the CDN.

Listed here are some stats on React Transition Group:

  • Reputation: 9.2k stars on Github, and greater than 8.4 million weekly downloads on NPM.
  • Documentation: Its docs are beginner-friendly; embody Codesandbox examples to higher illustrate.
  • Assist for Typescript: React transition group comes with the backing for TypeScript out of the field, and it may be put in utilizing the command beneath:
npm set up @sorts/react-transition-group
Enter fullscreen mode

Exit fullscreen mode

General, it is a good animation library to think about on your subsequent React mission.

3. React Movement

React Motion
React Motion is an animation library for React purposes that makes lifelike animations simpler to construct and implement.

It makes use of physics to create animations that really feel pure. All it’s important to do is present values for stiffness and damping inside certainly one of its parts.

  • stiffness refers back to the pace with which the vacation spot worth is reached.
  • damping is the friction encountered by the animated element throughout the transition.

Sequencing animations utilizing React Movement, nevertheless, just isn’t as straightforward and readable as a few of the alternate options resulting from its advanced nature.

Now, let’s examine some stats:

  • Reputation: 20.8k stars on Github, and greater than 611k weekly downloads on NPM
  • Documentation: They’ve well-documented examples of their options, and you may copy the supply code of a given element.
  • Assist for Typescript: You should utilize Typescript with React Movement by utilizing the type definitions.
  • Bundle dimension(minified): 19.8kB

4. React Spring

React Spring
React Spring is a spring-physics based mostly animation library that follows a contemporary method to animation.

It’s extremely versatile and covers most animations wanted on your Consumer interface.

React spring inherits some properties from React Movement, corresponding to ease of use, interpolation, and efficiency.

One actually cool particular about React Spring is the flexibility to use animations with out counting on React to render updates body by body.

Now, let’s see how React spring stacks up towards different React animation libraries:

  • Reputation: 23.1k stars on Github, and greater than 727k weekly downloads on NPM
  • Documentation: Properly-written and beginner-friendly documentation. You’ll be able to copy a code snippet from the documentation and take a look at or preview CodeSandbox.
  • Assist for Typescript: You’ll be able to set up the bundle for NPM or Yarn
  • Bundle dimension(minified): 172kB!


React and GSAP
The Greensock Animation Platform (GSAP) is a superb animation library for the online as a result of it allows you to animate absolutely anything that may be accessed with JavaScript, together with DOM Parts, SVGs, generic objects, canvases, and extra.

GSAP is a superb device to construct easy to very advanced physics-based animations. It permits builders to sequence movement and controls the animation dynamically.

GSAP can also be an ideal alternative as a result of it’s:

  • versatile
  • light-weight
  • quick (estimated to be 20x sooner than jQuery),
  • has a big and supportive group by way of the forums.

Now, for the report card,

  • Reputation: 14.1k stars on Github, and greater than 270k weekly downloads on NPM
  • Documentation: Has well detailed docs with Codepen examples. Should you want any assist, ask on the GreenSock [forums]
  • Assist for Typescript: Use the Typescript definitions on Github
  • Bundle dimension(minified): 62.1kB

Whilst you’re right here, try this article to discover ways to construct a modern preloader animation 🙂

6. Framer Movement

Framer Motion

Framer Motion is a well-liked React animation library. Like GSAP, Framer Movement permits us to use each easy and complicated animations and transitions to DOM components outlined in React parts.
Its syntax is simple to grasp which helps you make animations sooner and likewise improves the code readability.

General, Framer Movement is a really sturdy, extremely customizable, and highly effective library:

  • Reputation: 14.5k stars on Github, and greater than 1.1 million weekly downloads on NPM
  • Documentation: Straightforward to grasp and beginner-friendly; you could find the supply code of a given element within the docs and likewise view it in CodeSandbox.
  • Assist for Typescript: Framer movement helps Typescript off the bat. Even when the information are in TypeScript, you may write common ES6/JavaScript and they’ll nonetheless work.
  • Bundle dimension(minified): 140.7kB

Though it may get cumbersome as your animation components develop, and likewise has a a lot bigger bundle dimension when in comparison with another libraries, its broadly used these days, and deserves consideration on your subsequent React mission.


There are plenty of choices with regards to creating user-friendly animations and transitions in your React purposes. A lot of that are straightforward to get began with and customise.

On this article, you’ve gotten been launched to a few of these libraries, and hopefully, with the comparisons, you may select the choice that most accurately fits your animation wants on your subsequent React mission.

Additionally, when you’ve got used another animation libraries, kindly share them within the feedback part!

Thanks for studying, and have enjoyable animating 😉

Earlier than you go, try this listing of different library animations:

  • React-animations — the library is constructed on all animations with animate.css. It’s straightforward to make use of and has plenty of animation collections.
  • animated — Declarative Animations Library for React and React Native
  • Anime.js — Anime.js (/ˈæn.ə.meɪ/) is a light-weight JavaScript animation library with a easy, but highly effective API. It really works with CSS properties, SVG, DOM attributes and JavaScript Objects.
  • wow — Reveal Animations When You Scroll. Very Animate.css Good friend.
  • react-move — Stunning, data-driven animations for React.
  • velocity — Velocity is an animation engine with the identical API as jQuery’s $.animate().

Add a Comment

Your email address will not be published. Required fields are marked *