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

Add option to skip onChange handler when calling goToStep #34

Closed
kaldebert opened this issue Jan 23, 2020 · 2 comments · Fixed by #35
Closed

Add option to skip onChange handler when calling goToStep #34

kaldebert opened this issue Jan 23, 2020 · 2 comments · Fixed by #35
Labels

Comments

@kaldebert
Copy link

kaldebert commented Jan 23, 2020

Thank you for this library!
Would it possible to add an option to skip onChange handler when calling goToStep?
In my case, I push a new state to the browser's session history stack (see history) thank to the onChange handler. I don't use hash routing so I can't use the built-in routing.
I have also a listener to popstate event that updates current step (by calling goToStep) when the user clicks on back button for example. In this case, I would like to skip the onChange handler. Otherwise it pushes a new state and breaks the navigation.

Example:

  const { activeStepIndex, getStep, goToStep, nextStep, previousStep } = useWizard({
      onChange: ({ newStepIndex }) => {
        history.push("/step" + newStepIndex);
      }
  });

  useEffect(() => {
    const handlePopState = event => {
      // retrieve step index from path
      const newStepIndex = ...;
      if (newStepIndex !== -1) {
        // actually
        goToStep(newStepIndex);
        // expected
        goToStep(newStepIndex, { skipOnChange: true });
      }
    };

    window.addEventListener("popstate", handlePopState);

    return () => {
      window.removeEventListener("popstate", handlePopState);
    };
  });
@Jibbedi
Copy link
Owner

Jibbedi commented Jan 28, 2020

Hey!

Thanks for reaching out =)

We can definitely figure something out there. Give me a few days (I hope I can get to this before the weekend) to think about this =)

@Jibbedi
Copy link
Owner

Jibbedi commented Feb 2, 2020

🎉 This issue has been resolved in version 2.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants