Ver código fonte

slider sibling test

Ivan Asmer 3 anos atrás
pai
commit
b0f76ef484
1 arquivos alterados com 10 adições e 9 exclusões
  1. 10 9
      src/SliderImage.js

+ 10 - 9
src/SliderImage.js

@@ -14,15 +14,6 @@ export default ({images = [], className, onChange, onClick, ref, siblingOnly, cu
 
     const widthSum = (total, img) => total + (img?.getBoundingClientRect().width || 0)
 
-    useEffect(() => {
-        if (divRef.current){
-            const div           = divRef.current
-
-            const totalWidth    = imgs.reduce(widthSum, 0)
-            div.style.minWidth  = totalWidth + 'px'
-        }
-    }, [divRef, imgs])
-
     useEffect(() => {
         if (containerRef.current){
             const scrollTo = imgs.slice(0,propCurrent).reduce(widthSum, 0)
@@ -33,6 +24,16 @@ export default ({images = [], className, onChange, onClick, ref, siblingOnly, cu
         }
     },[propCurrent, imgs])
 
+    useEffect(() => {
+        if (divRef.current){
+            const div           = divRef.current
+
+            const totalWidth    = imgs.reduce(widthSum, 0)
+            div.style.minWidth  = totalWidth + 'px'
+        }
+    }, [divRef, imgs])
+
+
     console.log('CURRENT', current)
 
     const scrollToCurrent = () => {