Skip to content

Commit 6606d6a

Browse files
committed
chore: make use of use refs
1 parent 467d67f commit 6606d6a

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/wizard.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,51 +16,51 @@ const Wizard: React.FC<WizardProps> = React.memo(
1616
activeStep < React.Children.toArray(children).length - 1;
1717
hasPreviousStep.current = activeStep > 0;
1818

19-
const goToNextStep = React.useCallback(() => {
19+
const goToNextStep = React.useRef(() => {
2020
if (hasNextStep.current) {
2121
setActiveStep((activeStep) => activeStep + 1);
2222
}
23-
}, []);
23+
});
2424

25-
const previousStep = React.useCallback(() => {
25+
const previousStep = React.useRef(() => {
2626
if (hasPreviousStep.current) {
2727
setActiveStep((activeStep) => activeStep - 1);
2828
}
29-
}, []);
29+
});
3030

3131
// Callback to attach the step handler
32-
const handleStep = React.useCallback((handler: Handler) => {
32+
const handleStep = React.useRef((handler: Handler) => {
3333
nextStepHandler.current = handler;
34-
}, []);
34+
});
3535

36-
const doNextStep = React.useCallback(async () => {
36+
const doNextStep = React.useRef(async () => {
3737
if (hasNextStep.current && nextStepHandler.current) {
3838
try {
3939
setIsLoading(true);
4040
await nextStepHandler.current();
4141
setIsLoading(false);
4242
nextStepHandler.current = null;
43-
goToNextStep();
43+
goToNextStep.current();
4444
} catch (error) {
4545
setIsLoading(false);
4646
throw error;
4747
}
4848
} else {
49-
goToNextStep();
49+
goToNextStep.current();
5050
}
51-
}, [goToNextStep]);
51+
});
5252

5353
const wizardValue = React.useMemo(
5454
() => ({
55-
nextStep: doNextStep,
56-
previousStep,
57-
handleStep,
55+
nextStep: doNextStep.current,
56+
previousStep: previousStep.current,
57+
handleStep: handleStep.current,
5858
isLoading,
5959
activeStep,
6060
isFirstStep: Boolean(!hasPreviousStep.current),
6161
isLastStep: Boolean(!hasNextStep.current),
6262
}),
63-
[doNextStep, previousStep, isLoading, handleStep, activeStep],
63+
[activeStep, isLoading],
6464
);
6565

6666
const activeStepContent = React.useMemo(() => {

0 commit comments

Comments
 (0)