xstate
xstate copied to clipboard
[@xstate/react/useSpawn @xstate/vue/useSpawn] feat: spawn with option in useSpawn
Spawn behavior with options. Can find this actor with id.
const Test = () => {
const actor = useSpawn(bahavior, {
id: 'optionID'
});
return (
<>
<div data-testid="actor-id">{actor.id}</div>
</>
);
};
⚠️ No Changeset found
Latest commit: 9ab6a4718899c76a88165944969663d9f9bf3e13
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
👇 Click on the image for a new way to code review
-
Make big changes easier — review code in small groups of related files
-
Know where to start — see the whole change at a glance
-
Take a code tour — explore the change with an interactive tour
-
Make comments and review — all fully sync’ed with github
Legend
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
Latest deployment of this branch, based on commit 9ab6a4718899c76a88165944969663d9f9bf3e13:
Sandbox | Source |
---|---|
XState Example Template | Configuration |
XState React Template | Configuration |
Out of curiosity - could you describe what kind of use cases does useSpawn
satisfy for you?
Out of curiosity - could you describe what kind of use cases does
useSpawn
satisfy for you?
I have a machine which forward message to other actor. I marked every actor with id. Some of actors are very simple spawn form simmple behavior.
Could you prepare a simple codesandbox demonstrating the pattern? I'm wondering how exactly you have wired things up. It's mostly interesting from my point of view cause useSpawn
is sort of starting/managing/stopping an actor and I wonder why do you make this React's concern here and not let XState manage this using regular spawn
.
Could you prepare a simple codesandbox demonstrating the pattern? I'm wondering how exactly you have wired things up. It's mostly interesting from my point of view cause
useSpawn
is sort of starting/managing/stopping an actor and I wonder why do you make this React's concern here and not let XState manage this using regularspawn
.
codesandbox: https://codesandbox.io/s/elegant-hodgkin-19vx3q?file=/src/index.tsx you also can check this repo: https://github.com/cy-98/xstate-full-module
In this case, I want find a actor with special ID.
Could you prepare a simple codesandbox demonstrating the pattern? I'm wondering how exactly you have wired things up. It's mostly interesting from my point of view cause
useSpawn
is sort of starting/managing/stopping an actor and I wonder why do you make this React's concern here and not let XState manage this using regularspawn
.codesandbox: https://codesandbox.io/s/elegant-hodgkin-19vx3q?file=/src/index.tsx you also can check this repo: https://github.com/cy-98/xstate-full-module
In this case, I want find a actor with special ID.
Updated. Actually I want make an actors system that, remote components can registry an actor and other find it easy. A little bit like RPC
@Andarist Is it can be merged ?
Thank you for the PR. useSpawn
is removed in v5; instead, actors should be created directly.