Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
September 29, 2020 03:25 pm GMT

Why you should use Framer Motion

What is Framer Motion?

Think of Framer Motion as more of an improvement or reinvention of an existing animation library than a brand new one.

Framer Motion is the successor to Pose, which was one of the most popular animation libraries used with React. Like Pose, its built upon promotion, which is a low-level, unopinionated animation library, but it provides abstractions to streamline the process.

Framer Motion improves upon and simplifies the API in a way that couldnt have been done without breaking changes and rewriting. One difference is that whereas Framer Motion only has support for React, Pose has support for React-Native and Vue. If youre currently using Pose I would recommend updating to Framer Motion because Pose has been depreciated.

Why use Framer Motion?

  1. If most animation libraries use spring-based animations, then, why should you use Framer Motion? For starters, it has a great API that is simple and doesnt fill your components with extra code. In most cases, you can simply replace your HTML element with a motion element for example, div with motion.div, which results in the same markup but has additional props for animation.

  2. Framer Motion is capable of powering animations in Framer X, a prototyping tool, which makes the hand-off extremely convenient. The majority of designers have suffered a situation when they spend ages perfecting every little detail of design only to have it lost in the development process. Framer Motion lets you use the same animation library both in prototyping and production. This way you dont need to worry your animations are different from what youve intended them to be.

How do I start?

  1. Install Framer Motion package.

npm install framer-motion (if you are using npm)
or
yarn add framer-motion (if you are using yarn)

  1. Import motion component in your file.
import { motion } from 'framer-motion';
  1. Try to animate an element using animate attribute. Remember: you are not using more css syntax or attributes, they all are from Framer Motion
export default function App() {  return (    <motion.h2      animate={{ scale: 1.2 }}    >      Yayy, I am animated!!    </motion.h2>  )}

You can notice two important things:

  1. motion always comes before the html tag (just make shure on the documentation if Framer Motion supports)
  2. animate attribute pass an object (like the style={{}})

    1. See my repository about Framer Motion and learn how it works.
    2. See this playlist on YouTube about Framer Motion.

References

LogRocket
Medium


Original Link: https://dev.to/esaumorais/why-you-should-use-framer-motion-1gp8

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To