Questions tagged [xstate]

xstate is Javascript library for creating finite state machines and statecharts.

xstate is library for creating finite state machines and statecharts in JavaScript. Code and links to documentation found at https://github.com/davidkpiano/xstate

146 questions
1
vote
1 answer

XState: Express that a context is only relevant for certain states

I have a React component, it can transition between different states based on mouse-events. A simplified example: type Point = {x: number, y: number}; type MouseState = | {name: "idle"} | {name: "touched", point: Point} | {name: "moving",…
bzyr
  • 289
  • 1
  • 11
1
vote
1 answer

Global XState context using React useContext hook

Having some issues to implement XState in my app. I want to use the useContext for global context management together with XState to manage different workflows of the app. I'm trying to implement a use case consisting in a Modal launching a fetch…
1
vote
0 answers

How to update state machine

Is it possible to replace the currently initialized state machine in React? For example, I initialize a state machine via Provider with a dummy configuration. Then, upon entering a specific page in the app, I update it via context. Background of…
duduwe
  • 888
  • 7
  • 16
1
vote
1 answer

Awaiting asynchronous params when using xstate `useInterpret`

I want to enable persistance for react-native application. Following tutorial on https://garden.bradwoods.io/notes/javascript/state-management/xstate/global-state#rehydratestate I can't use asynchronous code inside xstate's hook…
Antio
  • 13
  • 1
  • 5
1
vote
1 answer

Is it possible to define in XState machine a transition from each state - just once

Suppose I have machine with states A, ..., Z. I want the machine to go to state Z if the machine receives the event { type: "END_OF_THE_WORLD" }, regardless in which state it is. Is it possible to define a transition that applies to all states, or…
1
vote
1 answer

Use XState in a nuxt composable

I want to use an xstate state machine in Nuxt 3 which is used over multiple components. I created a small example of how I want this to look like. I also use the nuxt-xstate module. State Machine: export default createMachine( { id:…
rajohs
  • 237
  • 1
  • 6
1
vote
0 answers

Use beta editor with inspect

I'm using inspect inspect({ iframe: false, }); Is it possible to pass a custom url to the inspect to use the new beta editor? Also, is it possible to hide the sidebar when opening the visualizer?
Otavio Bonder
  • 1,789
  • 4
  • 17
  • 35
1
vote
1 answer

XState: Types of property 'actions' are incompatible

I am writing my first XState-driven app in TypeScript, with the FAST framework from Microsoft. I am getting a compile-time error on my states.loading.invoke.onDone.actions property, that looks like this: export const questions = { initial:…
serlingpa
  • 12,024
  • 24
  • 80
  • 130
1
vote
0 answers

Is there a function for getting the parent state value when in a compounded state (hierarchical state) in xState?

I used the parent states name for some utility purposes, the problem is when trying to retrieve it from a child state as it returns an object with the parents state value as the object key. Below is the code to get the value when in the parent…
1
vote
1 answer

How to resume last state (history nodes)

I'm learning x-state and I'm overwhelmed about its functionality, but I'm having issues understanding history nodes. I'm creating a state which should hold the execution of the machine until an action is triggered: So if the machine is in…
Otavio Bonder
  • 1,789
  • 4
  • 17
  • 35
1
vote
1 answer

XState React - Invoke Service not triggered

I am using xstate with react to implement a basic login functionality. The code is here and the issue I am facing is, on the event AUTHENTICATING it is meant to invoke a service authenticateUser and it is not invoking. No visible errors in the…
Priyank Thakkar
  • 4,752
  • 19
  • 57
  • 93
1
vote
1 answer

Problem to check the current machine state using XState in React

im trying to check the Machine state from inside a function in a react component (state.value), but its never change the current state, it always prints the initial state, but if i put a onClick event in the component and call…
Leo Gersen
  • 13
  • 5
1
vote
1 answer

How to invoke a machine with context of the machine that invokes that machine?

Firstly, here’s the code. I need to fix. Basically, there are two machines: currentStateMachine: currently, I want to change the state manually (running send commands) once a second based on the real state; later, it might be better to run a…
tukusejssirs
  • 564
  • 1
  • 7
  • 29
1
vote
1 answer

Testing actions reliably

I'm using xstate to implement a login flow. I have a machine where the initialState invokes a Promise, and if it's rejected it will redirect to a state that has an entry action. I would like to test that the action is called at the right time…
Haythem Farhat
  • 737
  • 7
  • 13
1
vote
1 answer

unable to restore state machine with persisted state using xstate and react

I am trying to create a state machine which can persist the machine's state details at any given point in time and then restore the machine with the persisted state and context values on revisiting the page. The Xstate docs mention about persisting…
arvir
  • 101
  • 1
  • 10
1 2
3
9 10