Skip to main content
Module

x/xstate/src/getNextSnapshot.ts>getNextSnapshot

Actor-based state management & orchestration for complex app logic.
Go to Latest
function getNextSnapshot
import { getNextSnapshot } from "https://deno.land/x/xstate@xstate%405.9.1/src/getNextSnapshot.ts";

Determines the next snapshot for the given actorLogic based on the given snapshot and event.

If the snapshot is undefined, the initial snapshot of the actorLogic is used.

Examples

Example 1

  import { getNextSnapshot } from 'xstate';
  import { trafficLightMachine } from './trafficLightMachine.ts';

  const nextSnapshot = getNextSnapshot(
    trafficLightMachine, // actor logic
    undefined, // snapshot (or initial state if undefined)
    { type: 'TIMER' }); // event object

  console.log(nextSnapshot.value);
  // => 'yellow'

  const nextSnapshot2 = getNextSnapshot(
    trafficLightMachine, // actor logic
    nextSnapshot, // snapshot
    { type: 'TIMER' }); // event object

  console.log(nextSnapshot2.value);
  // =>'red'

Parameters

actorLogic: T
snapshot: SnapshotFrom<T>