Issue with going to specific step using 'nextStep' when we are at last step
shabith opened this issue · comments
Hi there!
When we are at the final step of the wizard, and if we want to go to a specific step, that functionality is not working.
I have created a small demo in codesandbox
So I did debug the code, and it seems like the issue here.
https://github.com/devrnt/react-use-wizard/blob/main/src/wizard.tsx#L20
const goToNextStep = React.useRef((stepIndex?: number) => {
if (hasNextStep.current) { // <-- this line
setActiveStep((activeStep) => stepIndex ?? activeStep + 1);
}
});
Is there any way to overcome this issue?
okay, I have fixed the issue :)
https://github.com/shabith/react-use-wizard/blob/main/src/wizard.tsx#L19-L27
Let me know if you want me to make a PR for this.
Hi, thanks for creating this issue. It is indeed not working as expected at the moment.
However that you pointed out a valid bug, your codesandbox is "working" as expected. nextStep
takes an optional index, however, this starts at 0. So in the codesandbox it should say nextStep(1)
, but this won't work because of this issue.
Brilliant! it is now fixed with the latest version. Thank you, @devrnt for fixing this quickly.