Export as code
Exporting as code is useful if you want to use your machine with XState inside your codebase or if you want to duplicate your machine without using Fork.
You can currently export your machine as JSON, JavaScript, and TypeScript code using the code panel in the right tool menu. You can also export as code from the Export machine dialog using the export icon button in the editor’s top bar.
Export code from the code panel​
- Open the Code panel from the right tool menu.
- Use the JSON, JavaScript, or TypeScript buttons to display the code in your preferred format in the text area.
- Use the Copy button to copy the code to your clipboard.
- Paste into your code editor.
Export code using the header export icon​
- Open the export Code modal using the export icon in the header.
- Use the JSON, JavaScript, or TypeScript button to copy the code in your preferred format to your clipboard.
- Paste into your code editor.
Export code from the machine menu​
- Open the machine menu by clicking the ellipsis button to the right of the machine name.
- Click the Export code button in the menu to open the Export machine dialog.
- Use the JSON, JavaScript, or TypeScript button to copy the code in your preferred format to your clipboard.
- Paste into your code editor.