Skip to content

TypeScript-first
state machinery.

Extensible state and state machine primitives with excellent type inference and autocomplete.
Get started →
npm install matchina
fig.01 — fetcher machine ● live
fetch resolve reject reset retry IdleLoadingSuccessError
fetchresolverejectresetretryIdleLoadingSuccessError
fetcher.ts typescript
const states = defineStates({
Idle: undefined,
Loading: undefined,
Success: (data: unknown) => data,
Error: (err: Error) => err,
});
const machine = createMachine(
states,
{
Idle: { fetch: 'Loading' },
Loading: { resolve: 'Success', reject: 'Error' },
Success: { reset: 'Idle' },
Error: { retry: 'Loading' },
},
'Idle'
);
2kb gzipped
0 dependencies
100% type-inferred