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 = {