pocketarc / use-journey

A React hook for building user journeys.
https://pocketarc.github.io/use-journey/
MIT License
4 stars 1 forks source link

Understanding `prevStep` and `nextStep` #1

Open brandonmcconnell opened 11 months ago

brandonmcconnell commented 11 months ago

So, I understand the need for prevStep and nextStep, determining how the previous and next steps are conditionally determined.

What I'm struggling to understand is how the previous and next steps are determined when the prevStep and nextStep options are omitted, seeing as they are both listed as optional.


@pocketarc Thanks btw for this hook. I was working on building basically the exact same hook—with the same name, go figure—last week before finding this one. I wad facing a lot of the same bloating and API challenges you likely faced, so using something like this, assuming you plan to maintain it, is a bug win 🙂

pocketarc commented 11 months ago

Ah, this is great then! I do maintain it, but it hasn't had the benefit of an outside perspective. It'll be great to see how it works for you, it might be that we come across parts of it that can be made even better.

To answer your question: Since the journey is an array, the default behaviour when either is omitted is to get the next/previous key in the array that is not skipped. If you just have a linear journey with some skippable steps, you don't need to mess with prevStep/nextStep at all, provided the array is in the right order.

Those are there for situations where the journey isn't linear and you need "next" to not be what would normally be next (for whatever reason that might be).

brandonmcconnell commented 11 months ago

@pocketarc Thanks! That makes sense.

I would love to see a more robust example using all of those extra features to better understand them.

I even like the ability to set prevStep conditionally. It's not a common scenario, but I can think of some situations where just because a user came from a step doesn't necessarily mean that's the step they ought to go back to, especially if a future step allows them to alter certain data set in a previous step.

pocketarc commented 11 months ago

Yeah, that would be ideal - I think the problem will be coming up with a realistic, thorough user journey that isn't too complicated to use as an example.

Open to suggestions though! And if you just want to talk through a journey you yourself are building (either here or some more convenient way), I'd be happy to!