feat: add onLoad callback to useRive

This commit is contained in:
Adam
2025-06-19 14:19:59 -07:00
parent 7b174f7f51
commit d808a8bdea
2 changed files with 6 additions and 0 deletions

View File

@@ -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) {

View File

@@ -15,6 +15,7 @@ export type UseRiveOptions = {
useOffscreenRenderer: boolean;
shouldResizeCanvasToContainer: boolean;
shouldUseIntersectionObserver?: boolean;
onLoad?: (rive: Rive) => void;
};
export type Dimensions = {