Zum Hauptinhalt springen
🕵️ SicherheitslückenCVE-2022-44368 | NASM 2.16 null pointer dereference (EUVD-2022-47313)(18.09.2026 um 03:34 Uhr)
🔧 ProgrammierungBuilding a Browser-Based Voxel Editor with React Three Fiber(18.09.2026 um 03:24 Uhr)
🔧 ProgrammierungThe Bottleneck Moved From Writing Code to Proving It(18.09.2026 um 03:32 Uhr)
🕵️ SicherheitslückenCVE-2022-44368 | NASM 2.16 null pointer dereference (EUVD-2022-47313)(18.09.2026 um 03:34 Uhr)
🔧 ProgrammierungBuilding a Browser-Based Voxel Editor with React Three Fiber(18.09.2026 um 03:24 Uhr)
🔧 ProgrammierungThe Bottleneck Moved From Writing Code to Proving It(18.09.2026 um 03:32 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

How to use a Lottie animation in your React app

Lottie is a library that allows you to use animations made in Adobe After Effects in your web projects. It's a great way to add some extra flair to your website or app.

In this article, I'll show you how I use Lottie animations in my React + Styled Components frontends.

Getting started

First I choose an animation from https://app.lottiefiles.com and export the **Lottie JSON** to my assets folder.

ViteJS provides a handy way to import JSON files:

import musicAnimation from '../../assets/lottiefiles/music.json';

(commentary on ViteJS)

Maybe it's time to show my ViteJS config actually:

import {defineConfig} from 'vite';
import react from '@vitejs/plugin-react';
import svgr from 'vite-plugin-svgr';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react({
      babel: {
        plugins: [
          [
            'babel-plugin-styled-components',
            {
              displayName: true,
              fileName: false
            }
          ]
        ]
      }
    }),
    svgr()
  ]
});

You can see how I import SVG and set up React + Styled Components.

Back to Lottie!

Using Lottie in React

So nothing complicated, just importing the Lottie Player and the json file:

import {Player as Lottie} from '@lottiefiles/react-lottie-player';
import musicAnimation from '../../assets/lottiefiles/music.json';

You can create a react component to set up the style and other properties:

const MusicComponent = () => (
  <Lottie
    hover
    loop={true}
    src={musicAnimation}
  />
);

And then use it in your app like any other component:

const $Lottie = styled(Lottie)`
  cursor: pointer;
  height: 100px;
`;

const Music = (props: {num: number}) => (
  <$Lottie hover loop={true} src={musicAnimation} />
);

// ... in the component

<$Row>
  {musicChoices.map(musicNum => (
    <Music key={`music-${musicNum}`} num={musicNum} />
  ))}
</$Row>

You'll find Lottie usage documentation here https://docs.lottiefiles.com/lottie-player/components/lottie-player/usage

Image description

Visualize the selection

When we click on the music, we want to change the color of the animation.

I created a variation of the Lottie animation with a different color:

import musicAnimation from '../../../assets/lottiefiles/music.json';
import musicSelectedAnimation from '../../../assets/lottiefiles/music-selected.json';
<Lottie
  hover
  loop={true}
  src={selected ? musicSelectedAnimation : musicAnimation}
/>

The issue is that the animation is stopped when we change the source.

So I added a simple isPlaying React local state to the component to start the colored one on switch:

const [isPlaying, setIsPlaying] = useState(false);

// ...

const play = async () => {
  audio.play();
  setIsPlaying(true);
};

const stop = () => {
  audio.pause();
  setIsPlaying(false);
};

Now we can use the autoplay property of the Lottie Player:

<Lottie
  hover
  loop={true}
  autoplay={isPlaying}
  src={selected ? musicSelectedAnimation : musicAnimation}
/>

Thanks for reading, see you around!

As always, feel free to comment on parts you need more explanations for, or share your thoughts on how you would have handled the parts you disagree with.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten How to use a Lottie animation in your React app

Thematisch verwandte Begriffe: Lottie, animation, your, React · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-61591 | djust provides Phoenix LiveView-style reactive server-side rendering for…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
News ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

↗ Original-Quelle