Minor Changes
-
28059b9f
#2197 Thanks @davidkpiano! - All spawned and invoked actors now have a.getSnapshot()
method, which allows you to retrieve the latest value emitted from that actor. That value may beundefined
if no value has been emitted yet.const machine = createMachine({ context: { promiseRef: null }, initial: 'pending', states: { pending: { entry: assign({ promiseRef: () => spawn(fetch(/* ... */), 'some-promise') }) } } }); const service = interpret(machine) .onTransition(state => { // Read promise value synchronously const resolvedValue = state.context.promiseRef?.getSnapshot(); // => undefined (if promise not resolved yet) // => { ... } (resolved data) }) .start(); // ...