diff --git a/src/hooks/useRive.tsx b/src/hooks/useRive.tsx index 264e719..2e94f7d 100644 --- a/src/hooks/useRive.tsx +++ b/src/hooks/useRive.tsx @@ -165,7 +165,7 @@ export default function useRive( const setCanvasRef: RefCallback = useCallback( (canvas: HTMLCanvasElement | null) => { if (canvas && riveParams) { - const {useOffscreenRenderer} = options; + const { useOffscreenRenderer } = options; const r = new Rive({ useOffscreenRenderer, ...riveParams, @@ -224,6 +224,17 @@ export default function useRive( }; }, [rive]); + /** + * Listen for changes in the animations params + */ + const animations = riveParams?.animations; + useEffect(() => { + if (rive && animations) { + rive.stop(rive.animationNames); + rive.play(animations); + } + }, [animations, rive]); + const Component = useCallback((props: ComponentProps<'div'>): JSX.Element => { return (