Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.3k
Basic Example of Providing actor with Input & Snapshot to react component tree#5389
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 datahttps://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. 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 constExisitingConnectFlow=({portfolioConnectItem,}:{portfolioConnectItem:PortfolioConnectItemFragment;})=>{const[saveSnapshot]=useUpdatePortfolioConnectSnapshotMutation();constactor=createActor(machine,{input:{portfolioConnect:portfolioConnectItem},snapshot:portfolioConnectItem.persistedSnapshot,});return(<div><ConnectMachineContext.Providerlogic={}// <--- only takes a machine logic? cant provide actual actor>// ...component tree that will pull from context to reference the actor</ConnectMachineContext.Provider></div>);}; Would the recommendation be to have my own provider to hold the actor using types viahttps://stately.ai/docs/typescript#actorreffromt? |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 comment
-
The provider supports an <ConnectMachineContext.Provideroptions={{input:{portfolioConnect:portfolioConnectItem},snapshot:portfolioConnectItem.persistedSnapshot}}> ...</ConnectMachineContext.Provider> |
BetaWas this translation helpful?Give feedback.