import { useActor } from '@xstate/react'; import { formMachine } from './formMachine'; import { createInspector } from '@statelyai/sdk'; const inspector = createInspector(); const USERNAME_STATUS = { pristine: '', debouncing: 'Waiting for you to stop typing…', checking: 'Checking availability…', available: 'Available', taken: 'Already taken' } as const; type UsernameState = keyof typeof USERNAME_STATUS; export default function App() { const [state, send] = useActor(formMachine, { inspect: inspector.inspect }); const usernameStates = [ 'debouncing', 'checking', 'available', 'taken' ] as const satisfies readonly UsernameState[]; const username: UsernameState = usernameStates.find((value) => state.matches({ username: value })) ?? 'pristine'; const email = (['valid', 'invalid'] as const).find((value) => state.matches({ email: value }) ) ?? 'pristine'; return (

Sign up

e.preventDefault()}>

{username === 'available' ? ( {USERNAME_STATUS.available} ) : ( USERNAME_STATUS[username] )}

{email === 'invalid' ? 'That does not look like an email address.' : email === 'valid' ? 'Looks good' : ''}

ada, grace and alan are taken.

); }