Skip to content

NexPB/xstate-react-patched

Repository files navigation

xstate-react-patched

This package contains utilities for using XState with React.

Note: This repository is a patched fork of the upstream @xstate/react package from hash 5dd9e25, maintained specifically to preserve support for the removed @xstate/fsm dependency.

Quick start

  1. Install xstate and @xstate/react:
npm i xstate@4.37.2 xstate-react-patched@3.2.2-patch.0
  1. Import the useMachine hook:
import { useMachine } from '@xstate/react';
import { createMachine } from 'xstate';

const toggleMachine = createMachine({
  id: 'toggle',
  initial: 'inactive',
  states: {
    inactive: {
      on: { TOGGLE: 'active' }
    },
    active: {
      on: { TOGGLE: 'inactive' }
    }
  }
});

export const Toggler = () => {
  const [state, send] = useMachine(toggleMachine);

  return (
    <button onClick={() => send('TOGGLE')}>
      {state.value === 'inactive'
        ? 'Click to activate'
        : 'Active! Click to deactivate'}
    </button>
  );
};

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors