Sfoglia il codice sorgente

18 react update and prerender check

asmer 3 mesi fa
parent
commit
3c8cce7edb
1 ha cambiato i file con 1 aggiunte e 1 eliminazioni
  1. 1 1
      src/SliderImage.js

+ 1 - 1
src/SliderImage.js

@@ -15,7 +15,7 @@ export default ({images = [], className, onChange, onClick, ref, current:propCur
     const widthSum = (total, img) => total + (img?.getBoundingClientRect().width || 0)
     const widthSum = (total, img) => total + (img?.getBoundingClientRect().width || 0)
 
 
     useEffect(() => {
     useEffect(() => {
-        if (containerRef.current && imgs.length === images.length){
+        if (containerRef.current && imgs.length === images.length && Number.isInteger(propCurrent) && propCurrent >= 0 && propCurrent < images.length){
             const scrollTo = imgs.slice(0,propCurrent).reduce(widthSum, 0)
             const scrollTo = imgs.slice(0,propCurrent).reduce(widthSum, 0)
             containerRef.current.scrollTo(scrollTo, 0)
             containerRef.current.scrollTo(scrollTo, 0)
             currentScrollPosition.current = scrollTo
             currentScrollPosition.current = scrollTo