Is there any other better alternate way to write the code with the same output ?
const handleGoBack = useCallback(() => {
if (previousStep === 0) {
openToast('warning', 'You are going back to dashboard');
navigate('/dashboard');
}
else {
dispatch(setCurrentStep(previousStep));
navigate(stepRoutes[previousStep.toString()]);
}
}, [dispatch, navigate, previousStep]);
return (
<div className={styles.backButton} onClick={handleGoBack}>
<IoArrowBackOutline className={styles.backIcon} />
<Localize>Back</Localize>
</div>
);
};
export default BackButton;
const stepRoutes: Record<string, string> = {
1: ‘/appointments/choose-specialty’,
2: ‘/appointments/select-doctor’,
3: ‘/appointments/time-slot’,
4: ‘/appointmenst/add-details’,
5: ‘/appointments/payment’,
};