statelyai / xstate

Actor-based state management & orchestration for complex app logic.
https://stately.ai/docs
MIT License
26.98k stars 1.24k forks source link

Bug: createActorContext is not starting the machine #4805

Closed santomegonzalo closed 6 months ago

santomegonzalo commented 6 months ago

XState version

XState version 5

Description

Hi, it is my first time using XState and everything looks really nice. I started using useMachine etc but then I decided to switch to createActorContext and this is when the issues started. I checked all examples and I can not see anything weird from my setup but basically when I wrapped my entire app with

const TheContext = createActorContext(machine);

...

<TheContext.Provider>
  {children}
</TheContext.Provider>

and when I try to call

const theActorRef = TheContext.useActorRef();
const { send, getSnapshot } = theActorRef;

console.log(getSnapshot());

I'm seeing the following issue:

Screenshot 2024-03-18 at 11 57 24

I don't understand whats going on at all.

Expected result

I should get the current snapshot fro the state instead of an error

Actual result

The app is crashing because nothing got initialized.

Screenshot 2024-03-18 at 11 58 17

Reproduction

none

Additional context

No response

davidkpiano commented 6 months ago

Hey @santomegonzalo, awesome that you're trying out XState! 🎉

Can you please provide a reproducible code example? You can use one of the React templates here: https://github.com/statelyai/xstate#templates

santomegonzalo commented 6 months ago

Hi, @davidkpiano, I will close this issue because I found what the problem was... when I was testing the library, I forgot to remove a createActor that was pointing to the same machine, and maybe there is a singleton happening in the background or something like that, but it was making some mess...

Thank you so much for your quick reply and awesome library!