Propiedades de las estados
Value: Indica el nombre del estado actual
Context: Da el contexto al estado actual
Event: El evento por el cual se llego al estado actual
Action: Un array de acciones a ejecutar en ese estado
Activities: Listado de actividades indicando si están en progreso o no
History: Indica el estado anterior
Meta: Los metadatos asociados al estado
NextEvents: Los posibles eventos a ejecutar partiendo del estado que nos encontremos
.
Metodos del estado
matches(nombre del estado)
can(nombre del evento)
.
src/Components/BaseLayout.js:
import React from 'react';
import { useMachine } from '@xstate/react';
import bookingMachine from '../Machines/bookingMachine';
export const BaseLayout = ()=> {
const [state,send] = useMachine(bookingMachine)
console.log('state machine', state)
console.log('matches(initial): ', state.matches('initial')) // true
console.log('matches(tickets): ', state.matches('tickets')) // false
console.log('can(START): ', state.can('START')) // true
console.log('can(FINISH): ', state.can('FINISH')) // false
return (
<div>State Machine</div>
)
}
CONSOLA:
matches(initial): true
matches(tickets): false
can(START): true
can(FINISH): false
¿Quieres ver más aportes, preguntas y respuestas de la comunidad?
o inicia sesión.