Skip to content

Commit

Permalink
try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
gdbroman committed Dec 6, 2024
1 parent b37a26b commit d3194ec
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/PromenadeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,28 @@ export const PromenadeProvider = ({
const goForward = useCallback(async () => {
if (isNextDisabled(index)) return;

await onNext?.(index);
try {
await onNext?.(index);

if (index < stepCount - 1) {
setIndex(index + 1);
if (index < stepCount - 1) {
setIndex(index + 1);
}
} catch (error) {
console.error(error);
}
}, [isNextDisabled, index, stepCount, onNext]);

const goBack = useCallback(async () => {
if (isBackDisabled(index)) return;

await onBack?.(index);
try {
await onBack?.(index);

if (index > 0) {
setIndex(index - 1);
if (index > 0) {
setIndex(index - 1);
}
} catch (error) {
console.error(error);
}
}, [isBackDisabled, index, stepCount, onBack]);

Expand Down

0 comments on commit d3194ec

Please sign in to comment.