xstate hello world

node v10.24.1
version: 1.0.0
endpointsharetweet
const { Machine, interpret } = require("xstate") const toggleMachine = Machine({ initial: 'inactive', states: { inactive: { on: { TOGGLE: 'active' } }, active: { on: { TOGGLE: 'inactive' } } } }); const toggleService = interpret(toggleMachine) .onTransition(state => console.log(state.value)) .start(); // => 'inactive' toggleService.send('TOGGLE').value; // => 'active' toggleService.send('TOGGLE').value; // => 'inactive'
Loading…

no comments

    sign in to comment