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

Bug: 'self' missing in context #4612

Closed
josephfh opened this issue Dec 21, 2023 · 0 comments · Fixed by #4616
Closed

Bug: 'self' missing in context #4612

josephfh opened this issue Dec 21, 2023 · 0 comments · Fixed by #4616
Labels

Comments

@josephfh
Copy link

XState version

XState version 5

Description

self is available to the assign function, which makes it possible to pass the parent machine down to a spawned child machine:

assign({
    spawnie: ({ self, spawn }) => spawn(someMachine, {
        input: { parent: self },
    })
})

However self is not available when specifying the initial context of a machine:

context: ({ self, spawn }) => spawn(someMachine, {
    input: { parent: self },
})

Expected result

It should be possible to deconstuct self in the context assignation

Actual result

It doesn't work. When trying to use context.parent.send(...) from the spawned child:

Uncaught TypeError: Cannot read properties of undefined (reading 'send')

Reproduction

https://stackblitz.com/edit/github-keqmzr-y5weyb?file=src%2FfeedbackMachine.ts

Additional context

No response

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.

1 participant