Repository navigation
Replies: 2 comments
|
Hey @JRebella just wondering if you ever found a proper fix for this or not? I'm also in need of a dynamic initial state right now with a React app. |
0 replies
|
The current idiomatic way is to have an initial starting state that checks input and routes based on that input, like you mentioned ("dummy" states) But you can also start with a specific state: const resolvedState = someMachine.resolveState({ value: 'login' });
const [state, send] = useMachine(someMachine, { snapshot: resolvedState });Or you could start the machine normally and use routable states to go directly to whatever state you want |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Just like context can be created dynamically based on the machine's input:

Allow something similar for determining the initial state of the machine, for example:
Example use case:
In many scenarios you want to implement persistence to your flow but using the persistence feature of xstate doesn't apply. For example in a register -> login sort of flow, you'll want to check your database to see if your user exists and resume the flow at the
loginstate, doesn't make sense to go around saving an xstate snapshot for cases like theseWorkarounds
Currently this logic is able to be implemented manually but its truly a pain to do so, requiring you to create a dummy
startingstate and mapping out every possible transition from thisstartingstate to any resumable state. Which also renders the flowchart of your machine unusableAll reactions