Code Component Development
Momen allows you to extend your applications by developing custom React components. These code components enable dynamic forms, data-driven charts, advanced animations, interactive maps, and more, greatly expanding the interactive capabilities of your projects.
Update (Sep 8, 2025): The CLI has been updated to version 0.4.16. All previous versions are now deprecated. Please reinstall the CLI and use the
momen updatecommand to upgrade any existing projects.Details
Prerequisites
- Proficiency in using the Momen platform for no-code development
- Coding skills and familiarity with TypeScript
- Understanding of React component development fundamentals and ability to write React component code independently
If you are new to React, refer to:
Getting Started
Before starting, please upgrade the CLI tool to the latest version and use the
momen updatecommand to upgrade. Node.js 18 or 20 is recommended. Node.js 22 is not supported.
1. Install Tool
Install the global CLI tool:
npm i -g momen-cli
# If you encounter slow network, you can switch sources and force reinstall:
npm i -g momen-cli --registry=https://registry.npmmirror.com --force2. View Help
After installation, run momen --help to see all commands and descriptions.
momen help
zvm cli 0.5.8
Usage: momen [options] [command]
Options:
-h, --help display help for command
Commands:
signin [options] <Username/Email> <Password> Signin to Momen.
create [options] <PrjName> Initializing project.
publish [options] Publish project.
...Common Commands
create <project_name>: Initialize projectsignin <username/email> <password>: Sign in to Momen platformsignout: Sign outupdate: Update project to the latest template structurepublish: Publish projectreinit: Re-register project ID, republish local project to platformreset: Reset template projectdelete: Delete projectunpublish <version>: Unpublish a specific versiondryrun: Check if the project can be publishedhelp: Display help
Development Workflow
1. Platform Login
Run the following command in your working directory.
> momen signin your_email your_password2. Create Project
Run the following command in any directory:
# create project_name
> momen create testThis step creates a new folder test containing all project files and template components. It also registers a code component project on the platform.
Edit Code
Navigate to your code component project directory and install dependencies:
> cd test
> npm installYou can send this development documentation to AI and then use AI to assist you with development.
Read Project Template Structure
A typical code component library project has the following structure:
- index.ts
- App.scss
- App.tsx
- index.css
- main.tsx
- vite-env.d.ts
- .eslintrc.cjs
- .gitignore
- codegen.ts
- HELPER.md
- index.html
- package.json
- README.md
- tsconfig.json
- tsconfig.node.json
- vite.config.ts
Where:
src/components: The main directory for declaring and editing code components.resources: The resource directory for storing icons and preview images.README.md: The project documentation file.
Mandatory Conventions
Each custom component must comply with the following rules:
-
Directory Structure Standards
- Components must have a directory under
src/components - Directory name must be the component name (start with uppercase letter)
- Directory must contain at least
index.tsandComponentName.tsx
- Components must have a directory under
-
Type Declaration Standards
The filesrc/components/ComponentName/ComponentName.tsxmust export the following 4 interfaces:Interface Name Purpose Type Requirements ${ComponentName}PropDataData passed from outside string,number,booleanand their arrays${ComponentName}StateDataState exposed to outside State<string | number | boolean>or their arrays${ComponentName}EventEvents triggered internally EventHandler${ComponentName}PropsComponent Props Contains propData,propState,eventCode Example:
import { EventHandler } from 'zvm-code-context'; export interface ConfirmModalPropData { buttonTitle: string; } export interface ConfirmModalStateData {} export interface ConfirmModalEvent { onConfirm?: EventHandler; } export interface ConfirmModalProps { propData: ConfirmModalPropData; propState: ConfirmModalStateData; event: ConfirmModalEvent; } export function ConfirmModal({ propData, event }: ConfirmModalProps) { // ... Business logic }
Interact with Host Project (Optional)
Please read: Code Component API Reference
Export Component
Expose newly edited components in src/components/index.ts.
5. Modify Project Basic Information (Metadata)
- package.json: Modify
name,description,version(follow npm standards). - resources directory: Add icons and preview images (webp/svg).
/resources/icon.webp(24x24)/resources/ComponentName/icon.webp(72x54)/resources/ComponentName/canvas.webp(300x200)
- README.md: Modify project and component documentation.
/README.md: Project documentation./src/components/ComponentName/README.md: Component documentation.
Debugging
Method 1: Direct Preview
npm run preview # Starts a local static resource server, default port 6326.Method 2: Combined with Momen Real-time Preview
- Ensure the project has been published historically.
- Run the following commands:
npm run preview # Starts a local static resource server, default port 6326.
npm run watch:build # Watches for local source code changes and automatically runs npm run build on save.- Open real-time preview in the Momen editor, click the “Debug” icon, and select port 6326.
- After code changes, refresh the real-time preview to see the latest effects.
Publish Project
Run the following command in the root directory:
momen publishIf publishing fails, you can run momen publish --verbose to get more detailed information, ask AI, or report errors in the community or user group.
Use in Momen
- Import: Click “Add Component”, select “Import”, and click “Import Component Library”.
- Sync: After code changes, sync or republish.
- Use: Drag the component to the canvas and configure the right property panel (data binding, events).