pinia-xstate

Put your xstate state machines into a global pinia store.
26,194
Install
npm install pinia-xstate
Latest Version:3.0.0
Vue:3
License:MIT
Last Updated:Feb 12, 2025
Links: npm
Maintainer: wobsoriano

pinia-xstate

Put your xstate state machines into a global pinia store.

Installation

npm install xstate pinia-xstate

Usage

import { defineStore } from 'pinia'
import { xstate } from 'pinia-xstate'
import { createMachine } from 'xstate'

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

// create a store using the xstate middleware
export const useToggleStore = defineStore(
  toggleMachine.id,
  xstate(toggleMachine)
)
<script setup>
import { useToggleStore } from './store/toggle'

const store = useToggleStore()
</script>

<template>
  <button @click="store.send({ type: 'TOGGLE' })">
    {{ store.state.value === 'inactive'
      ? 'Click to activate'
      : 'Active! Click to deactivate' }}
  </button>
</template>

License

MIT

Related Packages

@volverjs/query-vue

Repository pattern applied to a pinia store.

6,325 3
taro-plugin-pinia

Taro&vue3 支持使用 Pinia 进行状态管理的插件

3,934 10
xstate-vue

Simple xstate and vue3 integration

3,217
pinia-scope

Scoped Pinia Stores for Vue

3,115 0
pinia-persisted-plugin

将 Pinia 的状态持久化到本地存储(如LocalStorage或SessionStorage),并在页面刷新后...

1,387 0

Version History

Version Released License
3.0.0 MIT
2.2.1 MIT
2.2.0 MIT
2.1.0 MIT
2.0.2 MIT
Pre-releases (2)
Version Released License
2.0.0-beta.1 MIT
2.0.0-beta.0 MIT