Find Similar Packages for @xstate/react
@xstate/reactSimilar Packages:
Npm Package Weekly Downloads Trend
3 Years
🌟 Show real-time usage chart on @xstate/react's README.md, just copy the code below.
## Usage Trend
[![Usage Trend of @xstate/react](https://npm-compare.com/img/npm-trend/THREE_YEARS/@xstate/react.png)](https://npm-compare.com/@xstate/react#timeRange=THREE_YEARS)
Cumulative GitHub Star Trend
🌟 Show GitHub stars trend chart on @xstate/react's README.md, just copy the code below.
## GitHub Stars Trend
[![GitHub Stars Trend of @xstate/react](https://npm-compare.com/img/github-trend/@xstate/react.png)](https://npm-compare.com/@xstate/react)
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
@xstate/react1,366,53928,82136.2 kB1674 months agoMIT
README for @xstate/react

@xstate/react

This package contains utilities for using XState with React.

Quick start

  1. Install xstate and @xstate/react:
npm i xstate @xstate/react
  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({ type: 'TOGGLE' })}>
      {state.value === 'inactive'
        ? 'Click to activate'
        : 'Active! Click to deactivate'}
    </button>
  );
};