Skip to content

Commit

Permalink
fix(useStepper): fix expired action
Browse files Browse the repository at this point in the history
  • Loading branch information
vikiboss committed Sep 27, 2024
1 parent 17b44c6 commit 3abf4d7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/react-use/src/use-stepper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,17 @@ export function useStepper<T>(steps: T[], initialIdx?: number): UseStepperReturn
})

const goToNext = useStableFn(() => {
const { isLast } = latest.current
!isLast && actions.inc()
actions.setState((pre) => {
const isLast = pre === steps.length - 1
return isLast ? pre : pre + 1
})
})

const goToPrevious = useStableFn(() => {
const { isFirst } = latest.current
!isFirst && actions.dec()
actions.setState((pre) => {
const isFirst = pre === 0
return isFirst ? pre : pre - 1
})
})

const goBackTo = useStableFn((step: T) => isAfter(step) && goTo(step))
Expand Down

0 comments on commit 3abf4d7

Please sign in to comment.