Xstate: @xstate/react, useService : Type Error Cannot read property 'context' of undefined

Created on 3 Nov 2019  路  1Comment  路  Source: davidkpiano/xstate

Description
I am using a spawned actor as a prop, and then use that prop with the useService hook, similar to how the Reddit example with actors does it.

Expected Result
The return array of the useService hook would be valid.

Actual Result

TypeError
Cannot read property 'context' of undefined

Reproduction
Here is the code that is causing the error

Additional context
Love the library and the ideas. It's possible I'm doing something incorrectly here.

EDIT

Thanks for the speedy reply David. You鈥檙e awesome

invalid question

Most helpful comment

Close! The context property doesn't work the same way as assign. Try this:

// ...
        context: {
            flightTypeList,
            flightType: ONE_WAY_FLIGHT,
            firstFlightInput: undefined,
            secondFlightInput: undefined
        },
        entry: assign({
            firstFlightInput: () => spawn(createFlightInputMachine(), 'firstFlightInput'),
            secondFlightInput: () => spawn(createFlightInputMachine(), 'secondFlightInput')
        }),
// ...

>All comments

Close! The context property doesn't work the same way as assign. Try this:

// ...
        context: {
            flightTypeList,
            flightType: ONE_WAY_FLIGHT,
            firstFlightInput: undefined,
            secondFlightInput: undefined
        },
        entry: assign({
            firstFlightInput: () => spawn(createFlightInputMachine(), 'firstFlightInput'),
            secondFlightInput: () => spawn(createFlightInputMachine(), 'secondFlightInput')
        }),
// ...
Was this page helpful?
0 / 5 - 0 ratings

Related issues

hnordt picture hnordt  路  3Comments

dakom picture dakom  路  3Comments

3plusalpha picture 3plusalpha  路  3Comments

amelon picture amelon  路  3Comments

bradwoods picture bradwoods  路  3Comments