react-lottie-player vs react-lottie
React Animation Libraries
react-lottie-playerreact-lottieSimilar Packages:

React Animation Libraries

Both react-lottie and react-lottie-player are libraries designed to integrate Lottie animations into React applications, allowing developers to create rich, interactive animations easily. Lottie is an open-source animation file format that's lightweight and easy to use, enabling designers to create animations in Adobe After Effects and export them as JSON files. These libraries simplify the process of rendering Lottie animations in React, enhancing user interfaces with engaging visual effects. While they serve a similar purpose, they differ in terms of features and usage patterns, making it essential to understand their distinctions to choose the right one for your project.

Npm Package Weekly Downloads Trend

3 Years

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
react-lottie-player191,419-120 kB-2 years agoMIT
react-lottie01,73728 kB99a year agoMIT

Feature Comparison: react-lottie-player vs react-lottie

Animation Control

  • react-lottie-player:

    react-lottie-player offers comprehensive control over animations, including play, pause, stop, and the ability to adjust playback speed. It also supports event listeners, enabling developers to trigger actions based on animation events.

  • react-lottie:

    react-lottie provides basic control over animations, allowing you to start, stop, and loop animations. However, it lacks more advanced control features like playback speed adjustments or event listeners for animation progress.

Ease of Use

  • react-lottie-player:

    react-lottie-player is also user-friendly but comes with a slightly steeper learning curve due to its additional features. Developers may need to familiarize themselves with its API to fully utilize its capabilities.

  • react-lottie:

    react-lottie is relatively easy to set up and use, making it suitable for developers who want to quickly integrate Lottie animations without much overhead. It requires minimal configuration and is straightforward for basic use cases.

Customization

  • react-lottie-player:

    react-lottie-player provides extensive customization options, allowing developers to manipulate various aspects of the animation, such as speed, direction, and event handling, making it a better choice for complex animations.

  • react-lottie:

    react-lottie allows for some customization options, but it is limited compared to react-lottie-player. Developers can adjust basic properties like animation data and loop settings, but deeper customization may require additional work.

Performance

  • react-lottie-player:

    react-lottie-player is designed with performance in mind, providing better handling of complex animations and larger JSON files, ensuring smoother playback and less impact on application performance.

  • react-lottie:

    react-lottie is optimized for performance in most cases, but it may struggle with very complex animations or large JSON files, potentially leading to slower rendering times.

Community and Support

  • react-lottie-player:

    react-lottie-player benefits from a more active development community and frequent updates, providing better support and more features over time.

  • react-lottie:

    react-lottie has a solid community and support, but it may not be as actively maintained as react-lottie-player, which could affect long-term project viability.

How to Choose: react-lottie-player vs react-lottie

  • react-lottie-player:

    Choose react-lottie-player if you require more advanced features such as playback control, event handling, and a more flexible API. It is ideal for projects that need detailed control over animation states, including play, pause, and stop functionalities.

  • react-lottie:

    Choose react-lottie if you need a straightforward implementation for Lottie animations with basic controls. It is suitable for projects that require simple animation playback without extensive customization or advanced features.

README for react-lottie-player

Fully declarative React Lottie player

Inspired by several existing packages wrapping lottie-web for React, I created this package because I wanted something that just works and is easy to use. None of the alternatives properly handle changes of props like playing/pausing/segments. This lead to lots of hacks to get the animations to play correctly.

react-lottie-player is a complete rewrite using hooks 🎣 for more readable code, easy to use, seamless and fully declarative control of the lottie player.

Tests NPM JavaScript Style Guide

Features

Install

npm install --save react-lottie-player

Usage

import React from 'react'

import Lottie from 'react-lottie-player'
// Alternatively:
// import Lottie from 'react-lottie-player/dist/LottiePlayerLight'

import lottieJson from './my-lottie.json'

export default function Example() {
  return (
    <Lottie
      loop
      animationData={lottieJson}
      play
      style={{ width: 150, height: 150 }}
    />
  )
}

Example

Screenshot

🎛 Live demo

👩🏿‍💻 Example code

Lazy loading

Option 1: React code splitting (React.lazy)

Extract your Lottie animation into a separate component, then lazy load it:

// MyLottieAnimation.jsx

import Lottie from 'react-lottie-player';
import animation from './animation.json';

export default function MyLottieAnimation(props) {
  return <Lottie animationData={animation} {...props} />;
}

// MyComponent.jsx

import React from 'react';
const MyLottieAnimation = React.lazy(() => import('./MyLottieAnimation'));

export default function MyComponent() {
  return <MyLottieAnimation play />;
}

Option 2: dynamic import with state

const Example = () => {
  const [animationData, setAnimationData] = useState<object>();

  useEffect(() => {
    import('./animation.json').then(setAnimationData);
  }, []);

  if (!animationData) return <div>Loading...</div>;
  return <Lottie animationData={animationData} />;
}

Option 3: path URL

const Example = () => <Lottie path="https://example.com/lottie.json" />;

Imperative API (ref)

const lottieRef = useRef();

useEffect(() => {
  console.log(lottieRef.current.currentFrame);
}, [])

return <Lottie ref={lottieRef} />;

See also #11

LottiePlayerLight

The default lottie player uses eval. If you don't want eval to be used in your code base, you can instead import react-lottie-player/dist/LottiePlayerLight. For more discussion see #39.

Lottie animation track scrolling div

See example/App.jsx (ScrollTest) in live example.

Resize mode: cover

If you want the animation to fill the whole container, you can pass this prop. See also #55:

<Lottie rendererSettings={{ preserveAspectRatio: 'xMidYMid slice' }} />

API

See type definitions and lottie-web.

Releasing

  • Commit & wait for CI tests
  • np

Credits

License

MIT © mifi


Made with ❤️ in 🇳🇴

More apps by mifi.no

Follow me on GitHub, YouTube, IG, Twitter for more awesome content!