Basics/Splitting into files

Basics

Splitting into files

A licence form grows. Once it has a few sections, keep each in its own file, so you can find the café section without scrolling past everything else.

A section is a plain value. Move it to cafe.ts, export it, and give it the Section type, so the editor still checks every key:

import type { Section } from "#form-engine";

export const cafe: Section = {
  key: "cafe",
  title: "Café",
  fields: [ … ],
};

Then import it in form.ts:

import { defineForm } from "#form-engine";
import { cafe } from "./cafe";

export default defineForm({
  sections: [cafe],
});

Switch between the files with the tabs above the editor. The form on the right does not change: where a section is written makes no difference to the engine.

Up nextPicking several