1. 1
    Handle Complex State in Jotai with XState using atomWithMachine
    3m 30s

Handle Complex State in Jotai with XState using atomWithMachine

InstructorDaishi Kato

Share this video with your friends

Send Tweet

Jotai has a primitive and flexible API, because of this it's up to you on how you manage your state within an atom.

Sometimes your state is complex enough to warrant a sophisticated library for safer abstraction. This is where you can install xstate to your application and Jotai will work seamlessly with the state machines that you define using atomWithMachine.

This allows you to consume the machine like any other atom in your components with useAtom.

As an added bonus, I'll show you how to use xstate's visualizer to develop and interact with your state machine in dev tools.