Basic Example of Providing actor with Input & Snapshot to react component tree #5389
Unanswered
zacharyhansen
asked this question in
Q&A
Replies: 1 comment
-
|
The provider supports an <ConnectMachineContext.Provider
options={{
input: { portfolioConnect: portfolioConnectItem },
snapshot: portfolioConnectItem.persistedSnapshot
}}
>
...
</ConnectMachineContext.Provider> |
Beta Was this translation helpful? Give feedback.
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.
-
Hi all! I think I must be missing something obvious but I cannot figure out how to properly provide an actor I create in a react application to my component tree when it depends on input / persistent snapshots.
The examples here go into detail around how to provide a machine that doesnt depend on dynamic data https://stately.ai/docs/xstate-react#createactorcontextlogic but that is not useful if we are trying to start the actor with stored snapshots or input that is dynamic to the component (i.e. a specific route or other API driven information).
Examples like the following always reference the actor directly in the same component which works but is cumbersome in complex component trees.
https://codesandbox.io/p/sandbox/github/statelyai/xstate/tree/main/examples/tiles
https://codesandbox.io/p/sandbox/github/statelyai/xstate/tree/main/examples/todomvc-react
What I think would be ideal / really powerful is an example of how to provide my actor to my component tree when it depends on the component driven snapshot / input. Sort of like so
Would the recommendation be to have my own provider to hold the actor using types via https://stately.ai/docs/typescript#actorreffromt?
Beta Was this translation helpful? Give feedback.
All reactions