This library is no longer maintained. Making your own simple wrapper isn't difficult...
See original GitHub issueIf you need something complex, then react-lottie-player looks good. Otherwise the code below is all you need to display a lottie animation on your page. There is no play/pause logic here but that wouldn’t be too tricky to add. Just thought I’d post this in case anyone is wondering how much work it will be to get something working themselves.
import { useEffect, useRef } from "react"
import lottie from "lottie-web"
interface LottieProps {
animationData: any
width: number
height: number
}
export const Lottie = ({ animationData, width, height }: LottieProps) => {
const element = useRef<HTMLDivElement>(null)
const lottieInstance = useRef<any>()
useEffect(() => {
if (element.current) {
lottieInstance.current = lottie.loadAnimation({
animationData,
container: element.current,
})
}
return () => {
lottieInstance.current?.destroy()
}
}, [animationData])
return <div style={{ width, height }} ref={element}></div>
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:60
- Comments:9
Top Results From Across the Web
How to Write a Wrapper Library | Irrational Exuberance - Lethain
To write a wrapper library is to create a layer of abstraction on top of an existing body of functionality. Each additional layer...
Read more >Migrate from Enzyme | Testing Library
To ensure a successful migration, we recommend doing it incrementally by running the two test libraries side by side in the same application, ......
Read more >Why You Should (Often) Wrap Your Dependencies
Learning when and how to wrap you dependencies can save you lots of future suffering.
Read more >Using third-party libraries - always use a wrapper?
A huge advantage if you ever used a library which does not ... things that get more and more important the longer you...
Read more >Should you wrap 3rd party libraries that you adopt into your ...
The main factor for deciding to wrap a library or not is the impact a library change will have on the code ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I was getting this vibe too. Sad to see since it worked fairly well but this is a nice base for a shim. Thank you @funwithtriangles
Sorry, I don’t know the API very well! I was just posting a simple example that I thought might help others with similar simple needs. If you need anything more complex, then maybe react-lottie-player is more suitable.