
Learn to build state machines with XState and React, covering states, events, transitions. Explore nested and parallel machines, actions, guards, TypeScript, and Code Sandbox with video player and search component.
Explore state machines as a design approach for complex systems, detailing states, events, initial and final states, and transitions to keep web applications transparent and well described.
Explore how state machines represent a system at a moment using water’s four states as an analogy, and see how events trigger transitions and handlers drive changes in XState.
Learn to build a water state machine with XState and visualize transitions using XState Viz, defining states liquid, ice, and plasma and events like heat and freeze.
Connect a water state machine to a React app using useMachine to display current state and send heat or freeze events that transition between liquid, gas, plasma, and ice.
Understand actions in state machines: functions invoked by events or transitions as side effects, with inline or named definitions and entry or exit actions.
Create a video player state machine with XState and React, defining two states, playing and post, with play and stop events and entry actions, connected via useMachine.
Explore how context stores data in state machines, initialize and update it with the assign function, pass external values, and react to events like increment while referencing a video element.
connect a real video to the player machine by creating a React ref, injecting it into the machine context, and invoking video play and pause from machine actions.
Guards enable conditional transitions and actions in state machines using context and events. A guard function returns true or false to decide whether a transition occurs.
Explains internal, external, eventless, and forbidden transitions in state machines, covering entry and exit actions, nested states, dot-prefix transitions between child states, always handlers, and guards.
Add an optional autoplay flag to the video player state machine and enable guarded, eventless transitions from an unknown state to playing using extra options.
Learn how to invoke services (async functions returning promises) within state machines and execute parallel states, handling outputs as promises resolve or reject, with practical examples of parallel machine behavior.
Build a fetching machine with XState in React to manage API calls from idle to pending to success or error, updating context with fetched data and rendering results.
Discover how to invoke child state machines from a parent in XState and React, treat these machines as promises, and pass final-state data from child to parent.
Explore how delays work in XState using the after property to trigger transitions, such as one second to the dance state, plus self-sent events and dynamic delays via machine options.
This course is an introduction to finite state machines built with Javascript. State machines can describe complex applications straightforwardly, which makes them intuitive to work with and less error-prone. State machines can be easily integrated with React, which allows us to take a whole new approach for state management in React applications.
This course shows some basic concepts about state machines and their usage with XState. Also, it contains multiple coding examples, which allow students to have a better understanding of this topic.
Agenda:
Introduction to state machines
States, events, and transitions
Actions
Context
Guards
More on transition
Invoking services
Invoking machines
Delays
Alongside the presentations, we will also code some real-world examples, like:
Video player with autoplay option
Fetch machine for handling async requests
Search component with debounce