🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

lottie-react

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
l

lottie-react

Lottie for React

2.4.1
latest
99

Supply Chain Security

100

Vulnerability

100

Quality

77

Maintenance

100

License

Version published
Weekly downloads
858K
7.54%
Maintainers
1
Weekly downloads
 
Created
Issues
39

What is lottie-react?

The lottie-react npm package is a React wrapper for Lottie animations, which allows you to easily integrate and control Lottie animations in your React applications. Lottie is a library for rendering Adobe After Effects animations in real-time, which are exported as JSON files using the Bodymovin plugin.

What are lottie-react's main functionalities?

Basic Animation

This feature allows you to render a basic Lottie animation in your React component. You simply import the Lottie component and the animation JSON file, then use the Lottie component with the animationData prop.

import React from 'react';
import Lottie from 'lottie-react';
import animationData from './path/to/animation.json';

const BasicAnimation = () => {
  return <Lottie animationData={animationData} />;
};

export default BasicAnimation;

Controlled Animation

This feature allows you to control the playback of the Lottie animation. In this example, a button is used to toggle the animation between play and pause states using the isPaused prop.

import React, { useState } from 'react';
import Lottie from 'lottie-react';
import animationData from './path/to/animation.json';

const ControlledAnimation = () => {
  const [isPaused, setIsPaused] = useState(false);

  return (
    <div>
      <Lottie animationData={animationData} isPaused={isPaused} />
      <button onClick={() => setIsPaused(!isPaused)}>
        {isPaused ? 'Play' : 'Pause'}
      </button>
    </div>
  );
};

export default ControlledAnimation;

Looping Animation

This feature allows you to set the animation to loop continuously. By setting the loop prop to true, the animation will restart automatically after it finishes.

import React from 'react';
import Lottie from 'lottie-react';
import animationData from './path/to/animation.json';

const LoopingAnimation = () => {
  return <Lottie animationData={animationData} loop={true} />;
};

export default LoopingAnimation;

Event Listeners

This feature allows you to add event listeners to the Lottie animation. In this example, the onComplete event listener is used to log a message when the animation completes.

import React from 'react';
import Lottie from 'lottie-react';
import animationData from './path/to/animation.json';

const AnimationWithEvents = () => {
  const handleComplete = () => {
    console.log('Animation completed');
  };

  return <Lottie animationData={animationData} onComplete={handleComplete} />;
};

export default AnimationWithEvents;

Other packages similar to lottie-react

FAQs

Package last updated on 22 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts