Xstate: restore from state: Child state 'actions' does not exist on

Created on 8 Nov 2019  路  3Comments  路  Source: davidkpiano/xstate

Description

Using the counter example state machine I persist it like described in the docs

json = JSON.stringify(machine.state)`

Then later I want to load that state into my state machine

const counterService = interpret(counterMachine)
.start(counterMachine.resolve(State.create(JSON.parse(json))))

Expected Result

I was expecting this work.

Actual Result

I am getting the error:

Child state 'actions' does not exist on '(machine)'

Reproduction

https://codesandbox.io/s/xstate-example-template-yk6yd

bug

All 3 comments

Looking at the persisting state docs it looks like you want resolveState rather than resolve.

So your example would go from:

interpret(machine).start(
  machine.resolve(
    State.create(
      JSON.parse(json)
    )
  )
);

to:

interpret(machine).start(
  machine.resolveState(
    State.create(
      JSON.parse(json)
    )
  )
);

It certainly looks like it! Silly me. What is machine.resolve for then?

What is machine.resolve for then?

That is for resolving a state value, not a full state.

For example, someMachine.resolve('a') might return { a: { b: 'c' } }.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amelon picture amelon  路  3Comments

carlbarrdahl picture carlbarrdahl  路  3Comments

hnordt picture hnordt  路  3Comments

dakom picture dakom  路  3Comments

rodinhart picture rodinhart  路  3Comments