Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to control active step when activeStepIndex change #25

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/useWizard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useCallback } from 'react';
import { useState, useCallback, useEffect } from 'react';
import { Step } from './types';
import { isFunction } from './utils';

Expand All @@ -12,6 +12,12 @@ const useWizard = (
const isPrevDisabled: boolean = currentStep === 0;
const isFirstStep: boolean = currentStep === 0;
const isLastStep: boolean = currentStep >= total - 1;
useEffect(
() => {
setCurrentStep(activeStepIndex);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a comma here. Did you find it working in your local machine? I'm sure it didn't.

[setCurrentStep, activeStepIndex]
);
const goToPrev = useCallback(
() => setCurrentStep(Math.max(0, currentStep - 1)),
[setCurrentStep, currentStep]
Expand Down