File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,6 +69,7 @@ export default function useRive(
6969) : RiveState {
7070 const [ canvasElem , setCanvasElem ] = useState < HTMLCanvasElement | null > ( null ) ;
7171 const containerRef = useRef < HTMLElement | null > ( null ) ;
72+ const riveRef = useRef < Rive | null > ( null ) ;
7273
7374 const [ rive , setRive ] = useState < Rive | null > ( null ) ;
7475
@@ -135,6 +136,10 @@ export default function useRive(
135136 ...riveParams ,
136137 canvas : canvasElem ,
137138 } ) ;
139+ if ( riveRef . current != null ) {
140+ riveRef . current ! . cleanup ( ) ;
141+ }
142+ riveRef . current = r ;
138143 r . on ( EventType . Load , ( ) => {
139144 isLoaded = true ;
140145 // Check if the component/canvas is mounted before setting state to avoid setState
@@ -237,6 +242,14 @@ export default function useRive(
237242 } ;
238243 } , [ rive , canvasElem ] ) ;
239244
245+ useEffect ( ( ) => {
246+ return ( ) => {
247+ if ( riveRef . current != null ) {
248+ riveRef . current ! . cleanup ( ) ;
249+ }
250+ } ;
251+ } , [ ] ) ;
252+
240253 /**
241254 * Listen for changes in the animations params
242255 */
You can’t perform that action at this time.
0 commit comments