codegen/src
Browser-safe code generation utilities for Zod v4 form components.
Provides the building blocks for generating React form TSX files from a
FormField[] tree and a ZodFormsConfig. No Node.js dependencies — safe
to import in browser and server environments alike.
Key exports:
generateFormComponent— produce a complete TSX form component stringgetFileHeader— emit import declarations for generated filesrenderField— render a single field to its JSX stringbuildConfigSource— generate az2f.config.tsstarter filegetFieldTemplateSource— emit the preset FieldTemplate component sourcegenerateSchemaLiteFile— emit the lite schema file for optimized validation
Use When
- You are building a custom codegen pipeline on top of
walkSchema - You need to generate form components programmatically (e.g. a playground or IDE plugin)
Avoid When
- You just want to generate forms — use the CLI (
npx zod-to-form generate) instead
Pitfalls
- NEVER import this in a browser bundle that tree-shakes — the template strings are large.
Use dynamic
import()if you only need codegen in certain code paths.