Skip to content

Commit

Permalink
fix: getCurrentIndex returns wrong value when data count is < 3
Browse files Browse the repository at this point in the history
fix #299
  • Loading branch information
dohooo committed Nov 4, 2022
1 parent 7a82994 commit 7f94027
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/hooks/useCarouselController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
TCarouselProps,
WithTimingAnimation,
} from "../types";
import { convertToSharedIndex } from "../utils/computedWithAutoFillData";
import { computedRealIndexWithAutoFillData, convertToSharedIndex } from "../utils/computedWithAutoFillData";
import { dealWithAnimation } from "../utils/dealWithAnimation";
import { handlerOffsetDirection } from "../utils/handlerOffsetDirection";
import { round } from "../utils/log";
Expand Down Expand Up @@ -118,8 +118,15 @@ export function useCarouselController(options: IOpts): ICarouselController {
);

const getCurrentIndex = React.useCallback(() => {
return index.value;
}, [index]);
const realIndex = computedRealIndexWithAutoFillData({
index: index.value,
dataLength: dataInfo.originalLength,
loop,
autoFillData: autoFillData!,
});

return realIndex;
}, [index, autoFillData, dataInfo, loop]);

const canSliding = React.useCallback(() => {
return !dataInfo.disable;
Expand Down

0 comments on commit 7f94027

Please sign in to comment.