React Lottie Player is a component library for integrating Lottie animations into React applications with a fully declarative API. It wraps the core `lottie-web` library, aiming to provide a more robust experience by correctly handling prop changes for playback control and claiming to prevent memory leaks often associated with `lottie-web` repeaters. The current stable version, `2.1.0`, was published approximately two years ago, suggesting a mature and stable but not rapidly updated codebase for this specific package. Key differentiators include its declarative nature, seamless control of animation states (play, pause, loop, segments) via props, and the provision of a `LottiePlayerLight` variant that avoids the use of `eval` for environments with strict Content Security Policies.
npm install react-lottie-playerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import and render a Lottie animation using `react-lottie-player`. It shows loading animation data asynchronously, setting common props like `loop` and `play`, applying styles, and using a ref for imperative playback control (play, pause, stop, speed). It includes type definitions for clarity.
Consult the package's changelog and update your TypeScript types and component props accordingly. Ensure your `animationData` object conforms to the expected `lottie-web` JSON structure.
To avoid `eval`, import the `LottiePlayerLight` variant specifically: `import Lottie from 'react-lottie-player/dist/LottiePlayerLight'`. This version offers the same declarative API without using `eval` internally.
Implement dynamic imports or lazy loading for the `Lottie` component, ensuring it's only rendered on the client side. For example, in Next.js, use `next/dynamic` with `ssr: false`.
Monitor application performance, especially in scenarios with many animations or dynamic component lifecycles. Consider optimizing animation JSONs, using `LottiePlayerLight`, or carefully managing when animations are loaded and rendered (e.g., using intersection observers for animations off-screen).
Wrap the `Lottie` component with a dynamic import that disables SSR. In Next.js, this is `const DynamicLottie = dynamic(() => import('react-lottie-player'), { ssr: false });`.Double-check the `animationData` prop. Ensure it's a valid Lottie JSON object, correctly imported, and that `play` is set to `true`. Verify the `style` prop allows the component to be visible (e.g., has `width` and `height`).
Ensure `react-lottie-player` is compatible with your installed `lottie-web` version (if manually installed). Review `react-lottie-player`'s `package.json` for its `lottie-web` peer dependency. If issues persist, consider explicitly installing a compatible version of `@types/lottie-web` or `lottie-web` itself, or reporting an issue to the `react-lottie-player` maintainers.