Skip to content

Commit ec48759

Browse files
committed
refactor: change onLoad to onRiveReady
1 parent d808a8b commit ec48759

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/hooks/useRive.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,10 @@ export default function useRive(
131131
let r: Rive | null;
132132
if (rive == null) {
133133
const { useOffscreenRenderer } = options;
134+
const { onRiveReady, ...restRiveParams } = riveParams;
134135
r = new Rive({
135136
useOffscreenRenderer,
136-
...riveParams,
137+
...restRiveParams,
137138
canvas: canvasElem,
138139
});
139140
if (riveRef.current != null) {
@@ -143,8 +144,8 @@ export default function useRive(
143144
r.on(EventType.Load, () => {
144145
isLoaded = true;
145146

146-
if (options.onLoad) {
147-
options.onLoad(r!);
147+
if (onRiveReady) {
148+
onRiveReady(r!);
148149
}
149150

150151
// Check if the component/canvas is mounted before setting state to avoid setState

src/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import {
66
} from '@rive-app/canvas';
77
import { ComponentProps, RefCallback } from 'react';
88

9-
export type UseRiveParameters = Partial<Omit<RiveParameters, 'canvas'>> | null;
9+
export type UseRiveParameters = Partial<Omit<RiveParameters, 'canvas'>> & {
10+
onRiveReady?: (rive: Rive) => void;
11+
} | null;
1012

1113
export type UseRiveOptions = {
1214
useDevicePixelRatio: boolean;
@@ -15,7 +17,6 @@ export type UseRiveOptions = {
1517
useOffscreenRenderer: boolean;
1618
shouldResizeCanvasToContainer: boolean;
1719
shouldUseIntersectionObserver?: boolean;
18-
onLoad?: (rive: Rive) => void;
1920
};
2021

2122
export type Dimensions = {

0 commit comments

Comments
 (0)