Update animations on param change

This commit is contained in:
Arthur Vivian
2022-04-05 10:36:56 +01:00
committed by Arthur Vivian
parent 881e38fe6a
commit b13413ba8b

View File

@@ -165,7 +165,7 @@ export default function useRive(
const setCanvasRef: RefCallback<HTMLCanvasElement> = 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 (
<RiveComponent