Best Animation Libraries for ReactJS

Introduction

ReactJS is the most popular and loved framework among web developers for developing the frontend. From the launch, it has seen only growth. There are tons of libraries on the web for ReactJS that made React more awesome.

Today,…


This content originally appeared on DEV Community and was authored by Suraj Vishwakarma

Introduction

ReactJS is the most popular and loved framework among web developers for developing the frontend. From the launch, it has seen only growth. There are tons of libraries on the web for ReactJS that made React more awesome.

Today, we are going to look into some of the best animation libraries that will help you to create animation. These libraries are easy to install, learn and create animation.

So let's get started.

Framer Motion

A production-ready motion library for React. Utilize the power behind Framer, the best prototyping tool for teams. Proudly open source.

Framer Motion

Installation

npm i framer-motion

Usage

Imports

import { motion } from "framer-motion";

Code

In a motion.div tag, you define the animation of the component.

  • animate:You define the properties of the animation here. These are CSS properties.

  • transition: You define the transition properties here. Such as repeat, duration, etc.

<motion.div
        animate={{ x: 400, borderRadius: 50 }}
        transition={{ repeat: Infinity, duration: 1 }}
        className="circle"
      />

CodeSandbox Example

React Spring

react-spring is a spring-physics based animation library that should cover most of your UI related animation needs.

React Spring

Installation

npm i react-spring

Usage

Imports

import { useSpring, animated } from "react-spring";

Code

We have imported two things useSpring and animated.

  • useSpring: We define all the properties of the animation and transition here. from define the initial properties of the element and to is the final properties.

  • animate: It is used to define the element for the transition. It works as a component that takes style as the defined animation in useSpring.

  const props = useSpring({
    to: { y: 200, opacity: 0.5 },
    from: { y: 0, opacity: 1 },
  });

  <animated.div style={props} className="circle"></animated.div>

CodeSandbox Example

React Motion

A spring that solves your animation problems.

React Motion

Installation

npm i react-motion

Usage

Imports

import { Motion, spring } from "react-motion";

Code

  • Motion: Every animation and property is wrapped inside the Motion component. It contains the default style and animation properties using spring.
<Motion
        defaultStyle={{
          translateX: 0,
          opacity: 0,
        }}
        style={{
          translateX: spring(200),
          opacity: spring(1),
        }}
      >
        {(interpolatedStyles) => (
          <div
            style={{
              transform: `translateY(${interpolatedStyles.translateX}px)`,
              opacity: `${interpolatedStyles.opacity}`
            }}
            className="circle"
          ></div>
        )}
      </Motion>

CodeSandbox Example

Refersh to play the animation

Last Note

These are 3 Animation libraries for ReactJS that I like and use in my project for animation.

I hope you will try to use one of the libraries in your next project. Thanks for reading the post.


This content originally appeared on DEV Community and was authored by Suraj Vishwakarma


Print Share Comment Cite Upload Translate Updates
APA

Suraj Vishwakarma | Sciencx (2022-01-22T15:31:18+00:00) Best Animation Libraries for ReactJS. Retrieved from https://www.scien.cx/2022/01/22/best-animation-libraries-for-reactjs/

MLA
" » Best Animation Libraries for ReactJS." Suraj Vishwakarma | Sciencx - Saturday January 22, 2022, https://www.scien.cx/2022/01/22/best-animation-libraries-for-reactjs/
HARVARD
Suraj Vishwakarma | Sciencx Saturday January 22, 2022 » Best Animation Libraries for ReactJS., viewed ,<https://www.scien.cx/2022/01/22/best-animation-libraries-for-reactjs/>
VANCOUVER
Suraj Vishwakarma | Sciencx - » Best Animation Libraries for ReactJS. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/01/22/best-animation-libraries-for-reactjs/
CHICAGO
" » Best Animation Libraries for ReactJS." Suraj Vishwakarma | Sciencx - Accessed . https://www.scien.cx/2022/01/22/best-animation-libraries-for-reactjs/
IEEE
" » Best Animation Libraries for ReactJS." Suraj Vishwakarma | Sciencx [Online]. Available: https://www.scien.cx/2022/01/22/best-animation-libraries-for-reactjs/. [Accessed: ]
rf:citation
» Best Animation Libraries for ReactJS | Suraj Vishwakarma | Sciencx | https://www.scien.cx/2022/01/22/best-animation-libraries-for-reactjs/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.