1. 5
    Initialize a Xstate Machine with Jotai Atom in Atom Pattern
    3m 28s

Initialize a Xstate Machine with Jotai Atom in Atom Pattern

InstructorDaishi Kato

Share this video with your friends

Send Tweet

Sometimes adding initial values through the jotai Provider is not what you want. Provider will create a whole new store with atom values

One way to initialize a state machine inside Jotai is to turn our initial lightAtom into a function createLightAtom. This function will take an initial property that we can pass to createLightMachine when we declare the function. We will then useEffect to initialize our lightMachine.

There is a small limitation with this pattern, the machine is initialized with it's default value and then over ridden with the value we pass in the effect. The initial render will use that default value while the second render will have the value we passed in.

Gush
~ a year ago

Great - but it could use going into more details! for instance the ways it is possible to overcome the useEffect issue in the last lesson or more common uses. Overall great work, thanks!