|
@@ -15,13 +15,13 @@ 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){
|
|
|
|
|
|
+ if (containerRef.current && imgs.length === 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
|
|
setCurrent(propCurrent)
|
|
setCurrent(propCurrent)
|
|
}
|
|
}
|
|
- },[propCurrent])
|
|
|
|
|
|
+ },[propCurrent, imgs])
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
if (divRef.current){
|
|
if (divRef.current){
|