@moon-lottie/react
v0.1.5
Published
The official React wrapper for Moon Lottie
Downloads
555
Readme
@moon-lottie/react
The React wrapper for @moon-lottie/core.
Installation
npm install @moon-lottie/core @moon-lottie/reactBasic Usage
import { MoonLottiePlayer } from '@moon-lottie/react'
function App() {
return (
<MoonLottiePlayer
src="/animation.json"
autoplay
loop
wasmPath="/runtime/moon-lottie-runtime.wasm"
jsRuntimePath="/runtime/moon-lottie-runtime.js"
/>
)
}Ref API
import { useEffect, useRef } from 'react'
import { MoonLottiePlayer } from '@moon-lottie/react'
function App() {
const playerRef = useRef(null)
useEffect(() => {
playerRef.current?.whenReady()?.then(() => {
playerRef.current?.playSegments([[0, 30], [45, 90]], true)
})
}, [])
return (
<MoonLottiePlayer
ref={playerRef}
src="/animation.json"
wasmPath="/runtime/moon-lottie-runtime.wasm"
jsRuntimePath="/runtime/moon-lottie-runtime.js"
/>
)
}Common handle methods:
whenReady()play()/pause()/stop()/toggle()seek(frame)goToAndPlay(value, isFrame)/goToAndStop(value, isFrame)playSegments(segments, forceFlag)switchRuntime('auto' | 'wasm' | 'js')getState()/getBackend()/getPreference()
Props
Common props:
src/pathanimationDataautoplayloopspeeddirectionbackgroundrendererSettingsinitialSegmentwasmPathjsRuntimePathclassNamestyle
Events
React callback props:
onLoadonErroronRuntimeChangeonEnterFrameonPlayonPauseonCompleteonLoopCompleteonDestroy
Notes
- The current public renderer is
canvas. - Runtime preference defaults to
auto, which tries Wasm first and falls back to JS. - If you need direct imperative control outside React, use
loadAnimationfrom@moon-lottie/core.
