Sourcemap Explorer
Stack · npm package

@lottiefiles/react-lottie-player

Lottie web player wrapper for React

latest 3.6.0· MIT· 61 versions publishedView on npm

About

Lottie web player wrapper for React

lottielottiefilesreact

Live mirror of the GitHub README. Updated whenever the repo's default branch changes.

[!IMPORTANT] This package (@lottiefiles/react-lottie-player) is deprecated and no longer maintained. Please use @lottiefiles/dotlottie-react instead.


LottiePlayer React Component (Deprecated)

This is a React component for the Lottie Web Player

Demo

screencast

Documentation

In Javascript or TypeScript:
  1. Install package using npm or yarn.
npm install --save @lottiefiles/react-lottie-player
  1. Import package in your code.
import { Player, Controls } from '@lottiefiles/react-lottie-player';

Example/Development

  1. Clone repo

  2. run yarn install

  3. run yarn storybook

yarn storybook

Usage

Player component

Add the element Player and set the src prop to a URL pointing to a valid Lottie JSON.

<Player
  autoplay
  loop
  src="https://assets3.lottiefiles.com/packages/lf20_UJNc2t.json"
  style={{ height: '300px', width: '300px' }}
>
  <Controls visible={true} buttons={['play', 'repeat', 'frame', 'debug']} />
</Player>

Props

PropDescriptionTypeDefault
lottieRefGet lottie animation objectfunctionundefined
onEventListen for eventsfunctionundefined
onStateChangePlay state changesfunctionundefined
onBackgroundChangeListen for bg changesfunctionundefined
autoplayAutoplay animation on load.booleanfalse
backgroundBackground color.stringundefined
controlsShow controls.booleanfalse
directionDirection of animation.number1
hoverWhether to play on mouse hover.booleanfalse
keepLastFrameStop animation on the last frame.
Has no effect if loop is true.
booleanfalse
loopWhether to loop animation.booleanfalse
rendererRenderer to use.`"svg""canvas"`
speedAnimation speed.number1
styleThe style for the container.objectundefined
src (required)Bodymovin JSON data or URL to JSON.objectstring

Get Player instance

To call methods on the instance of the Player component. you may get a reference to the component and call the methods on ref.current. This is esentially reacts way of doing a document.getElementById(); You may then use this ref ie: player in the example below to call methods that are described in this documentation. See ref in react documentation

import React from 'react';
import { Player } from '@lottiefiles/react-lottie-player';

class App extends React.Component {
  constructor(props) {
    super(props);
    this.player = React.createRef(); // initialize your ref
  }
  render() {
    return (
      <Player
        ref={this.player} // set the ref to your class instance
        autoplay={false}
        loop={true}
        controls={true}
        src="https://assets3.lottiefiles.com/packages/lf20_XZ3pkn.json"
        style={{ height: '300px', width: '300px' }}
      ></Player>
    );
  }
}

export default App;

Get Lottie instance

The lottieRef prop returns the Lottie instance which you can use to set data and call methods as described in the bodymovin documentation.

import React from 'react';
import { Player } from '@lottiefiles/react-lottie-player';

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = { lottie: null }; // initialize your state
  }

  render() {
    return (
      <Player
        lottieRef={instance => {
          this.setState({ lottie: instance }); // the lottie instance is returned in the argument of this prop. set it to your local state
        }}
        autoplay={false}
        loop={true}
        controls={true}
        src="https://assets3.lottiefiles.com/packages/lf20_XZ3pkn.json"
        style={{ height: '300px', width: '300px' }}
      ></Player>
    );
  }
}

export default App;

Listening for events

import React from 'react';
import { Player } from '@lottiefiles/react-lottie-player';

class App extends React.Component {
  constructor(props) {
    super(props);
    this.player = React.createRef();
  }

  doSomething() {
    this.player.current.play(); // make use of the player and call methods
  }

  render() {
    return (
      <Player
        onEvent={event => {
          if (event === 'load') this.doSomething(); // check event type and do something
        }}
        ref={this.player}
        autoplay={false}
        loop={true}
        controls={true}
        src="https://assets3.lottiefiles.com/packages/lf20_XZ3pkn.json"
        style={{ height: '300px', width: '300px' }}
      ></Player>
    );
  }
}

export default App;

Events

The following events are exposed and can be listened to via addEventListener calls.

NameDescription
loadAnimation data is loaded.
errorAn animation source cannot be parsed, fails to load or has format errors.
readyAnimation data is loaded and player is ready.
playAnimation starts playing.
pauseAnimation is paused.
stopAnimation is stopped.
freezeAnimation is paused due to player being invisible.
loopAn animation loop is completed.
completeAnimation is complete (all loops completed).
frameA new frame is entered.

Methods

pause() => void

Pause animation play.

Returns

Type: void

play() => void

Start playing animation.

Returns

Type: void

setPlayerDirection(direction: 1 | -1 ) => void

Animation play direction.

Parameters
NameTypeDescription
valuenumberDirection values.
Returns

Type: void

setPlayerSpeed(speed?: number) => void

Sets animation play speed.

Parameters
NameTypeDescription
valuenumberPlayback speed.
Returns

Type: void

stop() => void

Stops animation play.

Returns

Type: void

setSeeker(frame: number, play: boolean) => void

Seek to a given frame.

Returns

Type: void

Contributing

We use changesets to maintain a changelog for this repository. When making any change to the codebase that impacts functionality or performance we require a changeset to be present.

To add a changeset run:

yarn run changeset

And select the type of version bump you'd like (major, minor, path).

You can document the change in detail and format it properly using Markdown by opening the ".md" file that the "yarn changeset" command created in the ".changeset" folder. Open the file, it should look something like this:

---
"@lottiefiles/pkg1": minor
"@lottiefiles/pkg2": major
---

This is where you document your **changes** using Markdown.

- You can write
- However you'd like
- In as much detail as you'd like

Aim to provide enough details so that team mates and future you can understand the changes and the context of the change.

You can commit your changes and the changeset to your branch and then create a pull request on the develop branch.

License

MIT License © LottieFiles.com

Quick facts

Latest version3.6.0
LicenseMIT
AuthorJawish Hameed
Installnpm install @lottiefiles/react-lottie-player
Direct dependencies1
Peer dependenciesreact

Common pairings

Packages this one expects to find in the same project. Each is also a Sourcemap Explorer detection target.

How Sourcemap Explorer detects @lottiefiles/react-lottie-player

We catch @lottiefiles/react-lottie-player from two complementary signals: bundled source paths and the embedded package.json. Modern bundlers (webpack, Vite, esbuild, Rollup, Turbopack) preserve the original node_modules/@lottiefiles/react-lottie-player/ paths inside the JavaScript sourcemap's sources[] array — that's the canonical signal. When the matching package.json is also captured in sourcesContent[], we read the exact version field — patch number included. No regex guessing, no version inference.

  1. 1

    Confirm the site exposes sourcemaps

    In DevTools Network, check the response headers of any application script for `SourceMap` or `X-SourceMap`. Failing that, fetch the script's last 4 KB and look for a `//# sourceMappingURL=` comment.

  2. 2

    Find the package in the bundle

    Open DevTools → Network → reload. Click any application script and look at its sourcemap. Inside, search `sources[]` for entries matching `node_modules/@lottiefiles/react-lottie-player/` — every match confirms the package is bundled. The matching `sourcesContent[i]` for `node_modules/@lottiefiles/react-lottie-player/package.json` gives you the exact installed version.

  3. 3

    Read the version directly from package.json

    Run `jq -r '. as $m | $m.sources | to_entries[] | select(.value | endswith("node_modules/@lottiefiles/react-lottie-player/package.json")) | $m.sourcesContent[.key] | fromjson | .version' bundle.js.map`. Sourcemap Explorer automates the same query in the popup.

Recent versions

Version
Released
1.0.0
1.0.1
1.0.2
2.0.0
2.0.1
2.1.1
2.1.2
2.1.3

FAQ

What is @lottiefiles/react-lottie-player used for?

Lottie web player wrapper for React

How can I tell if a website is using @lottiefiles/react-lottie-player?

Open the page in Chrome with the Sourcemap Explorer extension installed and read the Stack tab. We catch `@lottiefiles/react-lottie-player` from two complementary signals: `node_modules/@lottiefiles/react-lottie-player/` paths inside the JavaScript sourcemap, and the embedded `package.json` we read for exact-version detection. Without the extension you can do the same lookup manually in DevTools — the steps are listed in the "How Sourcemap Explorer detects" section above.

What is the latest version of @lottiefiles/react-lottie-player?

3.6.0, as published on the npm registry. The "Recent versions" table on this page lists the most recent 8 releases with their release dates. Sourcemap Explorer reports the version actually bundled into a site, which can lag the latest release by months on real-world deployments.

Where can I read more?

Project homepage: https://github.com/LottieFiles/lottie-react#readme. Source code: https://github.com/LottieFiles/lottie-react. Published on npm: https://www.npmjs.com/package/@lottiefiles/react-lottie-player. Licensed as MIT.

Keep reading on Sourcemap Explorer

Detected by Sourcemap Explorer

When a bundle ships sourcemaps, we read the embedded package.json for @lottiefiles/react-lottie-player and report the precise version. Without sourcemaps, an import / require in the page's scripts is enough to flag it.

Install free on Chrome