Lottie Animation View for React

1.2.10 · abandoned · verified Sun Apr 19

react-lottie is a React component that wraps `bodymovin.js` (now known as Lottie Web) to render animations exported from Adobe After Effects as JSON. The current stable version, 1.2.10, was released in 2018. It allows developers to integrate vector animations into React applications, offering programmatic control over playback (play, pause, stop), and supporting various After Effects features like shape layers, masks, and trim paths. Its key differentiators include enabling interactive animations with small file sizes, and the ability to load animation data from local assets or remote APIs. However, due to its age and lack of maintenance, developers should be aware of potential compatibility issues with modern React versions and ecosystem changes, making newer alternatives a more robust choice for contemporary projects.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to embed and control a Lottie animation using the `react-lottie` component, including play, pause, and stop functionality, with basic state management.

import React, { useState } from 'react';
import Lottie from 'react-lottie';
import * as animationData from './pinjump.json'; // Ensure this file exists in your project

// To run this example, first install: npm install --save react-lottie

export default function LottieControl() {
  const [isStopped, setIsStopped] = useState(false);
  const [isPaused, setIsPaused] = useState(false);

  const buttonStyle = {
    display: 'block',
    margin: '10px auto',
    padding: '8px 15px',
    fontSize: '16px',
    cursor: 'pointer'
  };

  const defaultOptions = {
    loop: true,
    autoplay: true, 
    animationData: animationData, // The imported JSON animation data
    rendererSettings: {
      preserveAspectRatio: 'xMidYMid slice'
    }
  };

  return (
    <div style={{ textAlign: 'center', padding: '20px' }}>
      <h1>Lottie Animation Example</h1>
      <Lottie 
        options={defaultOptions}
        height={400}
        width={400}
        isStopped={isStopped}
        isPaused={isPaused}
      />
      <button style={buttonStyle} onClick={() => setIsStopped(true)}>Stop</button>
      <button style={buttonStyle} onClick={() => setIsStopped(false)}>Play</button>
      <button style={buttonStyle} onClick={() => setIsPaused(!isPaused)}>Pause/Resume</button>
    </div>
  );
}

view raw JSON →