### Install react-lottie-player
Source: https://github.com/mifi/react-lottie-player/blob/master/README.md
Install the package using npm.
```bash
npm install --save react-lottie-player
```
--------------------------------
### Imperative API Usage with useRef
Source: https://github.com/mifi/react-lottie-player/blob/master/README.md
Accesses the Lottie player's imperative API using a ref to control playback or get frame information.
```jsx
const lottieRef = useRef();
useEffect(() => {
console.log(lottieRef.current.currentFrame);
}, [])
return ;
```
--------------------------------
### Using LottiePlayerLight
Source: https://github.com/mifi/react-lottie-player/blob/master/README.md
Imports the LottiePlayerLight version to avoid using 'eval' for animation loading.
```jsx
import Lottie from 'react-lottie-player/dist/LottiePlayerLight'
```
--------------------------------
### Configure Renderer with `rendererSettings`
Source: https://context7.com/mifi/react-lottie-player/llms.txt
Pass renderer-specific options to lottie-web via `rendererSettings`. Use `preserveAspectRatio: 'xMidYMid slice'` for cover behavior, similar to CSS `object-fit: cover`.
```jsx
import Lottie from 'react-lottie-player';
import animationData from './animation.json';
export default function CoverAnimation() {
return (
);
}
```
--------------------------------
### Select Renderer with `renderer`
Source: https://context7.com/mifi/react-lottie-player/llms.txt
Choose the lottie-web renderer using the `renderer` prop. Options include `'svg'` (default), `'canvas'`, or `'html'`. Changing this prop re-initializes the animation.
```jsx
import Lottie from 'react-lottie-player';
import animationData from './animation.json';
export default function CanvasRenderer() {
return (
);
}
```
--------------------------------
### Use CSP-Safe LottiePlayerLight Build
Source: https://context7.com/mifi/react-lottie-player/llms.txt
Import LottiePlayerLight from 'react-lottie-player/dist/LottiePlayerLight' for environments with strict Content Security Policies. This build omits expression support (which requires eval) and is smaller.
```jsx
import React from 'react';
// Use the light build — no eval, smaller bundle, CSP-safe
import LottieLight from 'react-lottie-player/dist/LottiePlayerLight';
import animationData from './simple-animation.json'; // must not use expressions
export default function CspSafeAnimation() {
return (
);
}
```
--------------------------------
### Setting Resize Mode to Cover
Source: https://github.com/mifi/react-lottie-player/blob/master/README.md
Configures the Lottie animation to fill its container using the 'rendererSettings' prop with 'preserveAspectRatio'.
```jsx
```
--------------------------------
### Basic Usage of Lottie Player
Source: https://github.com/mifi/react-lottie-player/blob/master/README.md
Import and use the Lottie component with animation data and playback controls. Supports loop and custom styles.
```jsx
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 (
)
}
```
--------------------------------
### Loading Lottie Animation from a URL
Source: https://github.com/mifi/react-lottie-player/blob/master/README.md
Loads a Lottie animation directly from a specified URL using the 'path' prop.
```jsx
const Example = () => ;
```
--------------------------------
### Basic Lottie Animation with react-lottie-player
Source: https://context7.com/mifi/react-lottie-player/llms.txt
Renders a basic Lottie animation using the LottiePlayer component. Ensure you have a local animation JSON file and import it.
```jsx
import React from 'react';
import Lottie from 'react-lottie-player';
import animationData from './animation.json';
export default function BasicAnimation() {
return (
);
}
```
--------------------------------
### play Prop
Source: https://context7.com/mifi/react-lottie-player/llms.txt
Control animation playback declaratively using the `play` prop. Set to `true` to play and `false` to pause. Changes are applied instantly.
```APIDOC
## play Prop
### Description
A boolean that controls playback. `true` plays the animation; `false` pauses it. Changing this prop at any time correctly starts or stops playback, including when combined with `segments` or `direction`.
### Usage
```jsx
import React, { useState } from 'react';
import Lottie from 'react-lottie-player';
import animationData from './animation.json';
export default function PlayPauseControl() {
const [playing, setPlaying] = useState(false);
return (
);
}
```
```
--------------------------------
### Configure Lottie Animation Looping
Source: https://context7.com/mifi/react-lottie-player/llms.txt
Control animation looping with the loop prop. Accepts true for infinite looping, false to play once, or a positive integer for a specific number of loops.
```jsx
import React, { useState } from 'react';
import Lottie from 'react-lottie-player';
import animationData from './animation.json';
export default function LoopControl() {
// Play exactly 3 times, then stop
return (
);
}
```
--------------------------------
### Handle Lottie Animation Events with Callbacks
Source: https://context7.com/mifi/react-lottie-player/llms.txt
Use event callback props like onLoad, onComplete, onLoopComplete, onSegmentStart, and onEnterFrame to react to animation lifecycle events. Ensure proper cleanup to prevent memory leaks.
```jsx
import React, { useState } from 'react';
import Lottie from 'react-lottie-player';
import animationData from './animation.json';
export default function EventCallbacks() {
const [events, setEvents] = useState([]);
const log = (name) => setEvents((prev) => [...prev.slice(-9), name]);
return (
);
}
```
--------------------------------
### Load Lottie Animation from Remote URL
Source: https://context7.com/mifi/react-lottie-player/llms.txt
Load animation JSON from a remote URL using the path prop. This is mutually exclusive with the animationData prop. Ensure the URL points to a valid Lottie JSON file.
```jsx
import Lottie from 'react-lottie-player';
export default function RemoteAnimation() {
return (
);
}
```
--------------------------------
### Lazy Loading Lottie Animation with Dynamic Import
Source: https://github.com/mifi/react-lottie-player/blob/master/README.md
Loads Lottie animation data dynamically using useEffect and import, displaying a loading state until data is available.
```jsx
const Example = () => {
const [animationData, setAnimationData] = useState