Skip to main content

Creating a Machine

Once you've defined your machine config, use retomus.createMachine() to generate a running instance of the machine.


πŸ› οΈ Basic Usage​

const counterMachine = retomus.createMachine(machineConfig);

This returns a stateful instance with hooks and APIs like:

  • .useState()
  • .useAction()
  • .useStatus()
  • .setup()

🎯 Unique ID Requirement​

Each machine must have a unique id:

const machineConfig = {
id: 'myMachine',
...
};

Reusing the same id for multiple machines will result in unexpected behavior.


πŸ’‘ Register Early​

It’s common to register machines at app startup, especially if they are global or shared across components.