From 99f44bc995cf45970b151528aa9478cc03e1ceef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=9D=B1=E6=BE=94?= Date: Sun, 1 May 2022 22:39:49 +0800 Subject: [PATCH] fix: current index doesn't reset when modify data length fix #163 --- src/hooks/useCommonVariables.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hooks/useCommonVariables.ts b/src/hooks/useCommonVariables.ts index 3b3b27fc..8b2ca188 100644 --- a/src/hooks/useCommonVariables.ts +++ b/src/hooks/useCommonVariables.ts @@ -11,7 +11,7 @@ interface ICommonVariables { export function useCommonVariables( props: TInitializeCarouselProps ): ICommonVariables { - const { vertical, height, width, data, defaultIndex } = props; + const { vertical, height, width, data, defaultIndex, rawData } = props; const size = vertical ? height : width; const validLength = data.length - 1; const defaultHandlerOffsetX = -Math.abs(defaultIndex * size); @@ -23,7 +23,7 @@ export function useCommonVariables( * #163 add deps with rawData. **/ handlerOffsetX.value = defaultHandlerOffsetX; - }, [vertical, handlerOffsetX, defaultHandlerOffsetX]); + }, [vertical, handlerOffsetX, defaultHandlerOffsetX, rawData]); return { size,