From d808a8bdea4e2a87ca4940dfed43775e5abe016d Mon Sep 17 00:00:00 2001 From: Adam <67035612+damzobridge@users.noreply.github.com> Date: Thu, 19 Jun 2025 14:19:59 -0700 Subject: [PATCH] feat: add onLoad callback to useRive --- src/hooks/useRive.tsx | 5 +++++ src/types.ts | 1 + 2 files changed, 6 insertions(+) diff --git a/src/hooks/useRive.tsx b/src/hooks/useRive.tsx index 93bc471..7e27749 100644 --- a/src/hooks/useRive.tsx +++ b/src/hooks/useRive.tsx @@ -142,6 +142,11 @@ export default function useRive( riveRef.current = r; r.on(EventType.Load, () => { isLoaded = true; + + if (options.onLoad) { + options.onLoad(r!); + } + // Check if the component/canvas is mounted before setting state to avoid setState // on an unmounted component in some rare cases if (canvasElem) { diff --git a/src/types.ts b/src/types.ts index 0eebf66..5894f97 100644 --- a/src/types.ts +++ b/src/types.ts @@ -15,6 +15,7 @@ export type UseRiveOptions = { useOffscreenRenderer: boolean; shouldResizeCanvasToContainer: boolean; shouldUseIntersectionObserver?: boolean; + onLoad?: (rive: Rive) => void; }; export type Dimensions = {