From 5d3ba03c3cb9cdc4065875dc9ce15bce91ff7bf8 Mon Sep 17 00:00:00 2001
From: me <bhavesh.pareek36@gmail.com>
Date: Mon, 1 Feb 2021 22:28:58 +0530
Subject: [PATCH] clear canvas if data changes

---
 src/index.tsx | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/index.tsx b/src/index.tsx
index 704e3c4..fa88d2b 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -1,8 +1,9 @@
-import * as React from 'react'
-import styles from './styles.module.css'
 import './setup'
 
+import * as React from 'react'
+
 import { SpeRuntime } from './spline-runtime.js'
+import styles from './styles.module.css'
 
 interface Props {
   scene: object
@@ -10,14 +11,19 @@ interface Props {
 }
 
 export const Spline = ({ scene, assets }: Props) => {
+  const ref = React.useRef()
   React.useEffect(() => {
+    const { current } = ref
+    if (current) {
+      current.width = current.width
+    }
     const splineRuntime = new SpeRuntime(scene, assets)
     splineRuntime.run()
-  }, [])
+  }, [scene, assets])
   return (
     <div>
       <div className={styles.container}>
-        <canvas id='canvas3d' className={styles.canvas}></canvas>
+        <canvas id='canvas3d' className={styles.canvas} ref={ref}></canvas>
       </div>
     </div>
   )