Skip to content

Commit 444c30b

Browse files
committed
feat: add onLoad callback to useRive
1 parent 7b174f7 commit 444c30b

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

src/hooks/useRive.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ export default function useRive(
142142
riveRef.current = r;
143143
r.on(EventType.Load, () => {
144144
isLoaded = true;
145+
146+
if (options.onLoad) {
147+
options.onLoad(r!);
148+
}
149+
145150
// Check if the component/canvas is mounted before setting state to avoid setState
146151
// on an unmounted component in some rare cases
147152
if (canvasElem) {

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type UseRiveOptions = {
1515
useOffscreenRenderer: boolean;
1616
shouldResizeCanvasToContainer: boolean;
1717
shouldUseIntersectionObserver?: boolean;
18+
onLoad?: (rive: Rive) => void;
1819
};
1920

2021
export type Dimensions = {

0 commit comments

Comments
 (0)