smolter
Types

Submission

Values accepted by Preact programmatic submissions.

Compatibility

ReactAvailable in this renderer's browser integration.
React SSRAvailable to this renderer's SSR integration; browser event handlers run after hydration.
PreactAvailable in this renderer's browser integration.
Preact SSRAvailable to this renderer's SSR integration; browser event handlers run after hydration.

Import from @kasperrt/smolter/react @kasperrt/smolter/preact

Signature

type Submission = FormData | HTMLFormElement | Record<string, unknown>;

Supported values

Submission is FormData, HTMLFormElement, or Record<string, unknown>. FormData is passed through unchanged. A form element is converted to FormData. Ordinary object fields are converted with String(value), so use FormData for files or repeated field names.

import type { Submission } from "@kasperrt/smolter/preact";

const fields = new FormData();
fields.append("tag", "routing");
fields.append("tag", "typescript");

const submission: Submission = fields;

Structured JSON

With encType: "application/json", the object is serialized into a _payload form field. The route handler reads it with readSubmission(request). This encoding does not send a raw application/json body. Avoid including a form element or FormData when the intended payload is structured JSON; pass the object itself.

Destinations

The value contains the submission body, not its destination. Select the route with options.action. Programmatic submission of a form element reads its controls; supply the intended action and method explicitly. For an independent request and result state, use useFetcher rather than useSubmit.

View implementation ↗