refactor: change onLoad to onRiveReady

This commit is contained in:
Adam
2025-06-23 09:27:36 -07:00
parent d808a8bdea
commit ec4875933c
2 changed files with 7 additions and 5 deletions

View File

@@ -131,9 +131,10 @@ export default function useRive(
let r: Rive | null;
if (rive == null) {
const { useOffscreenRenderer } = options;
const { onRiveReady, ...restRiveParams } = riveParams;
r = new Rive({
useOffscreenRenderer,
...riveParams,
...restRiveParams,
canvas: canvasElem,
});
if (riveRef.current != null) {
@@ -143,8 +144,8 @@ export default function useRive(
r.on(EventType.Load, () => {
isLoaded = true;
if (options.onLoad) {
options.onLoad(r!);
if (onRiveReady) {
onRiveReady(r!);
}
// Check if the component/canvas is mounted before setting state to avoid setState

View File

@@ -6,7 +6,9 @@ import {
} from '@rive-app/canvas';
import { ComponentProps, RefCallback } from 'react';
export type UseRiveParameters = Partial<Omit<RiveParameters, 'canvas'>> | null;
export type UseRiveParameters = Partial<Omit<RiveParameters, 'canvas'>> & {
onRiveReady?: (rive: Rive) => void;
} | null;
export type UseRiveOptions = {
useDevicePixelRatio: boolean;
@@ -15,7 +17,6 @@ export type UseRiveOptions = {
useOffscreenRenderer: boolean;
shouldResizeCanvasToContainer: boolean;
shouldUseIntersectionObserver?: boolean;
onLoad?: (rive: Rive) => void;
};
export type Dimensions = {