smolter
Types

SubmissionOptions

Route target, method, encoding, and navigation options for Preact 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

interface SubmissionOptions {
  action?: string;
  encType?: string;
  method?: string;
  replace?: boolean;
  preventScrollReset?: boolean;
}

Fields

action is an optional route URL, defaulting to the current route URL. method defaults to POST. encType: "application/json" enables the structured _payload encoding read by readSubmission. replace and preventScrollReset apply to GET navigation through useSubmit; they do not change the HTTP body.

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

const options: SubmissionOptions = {
  action: "/tasks/7",
  method: "PATCH",
  encType: "application/json",
};

Reads and mutations

useSubmit handles GET by putting successful form controls into the destination query string and navigating there. For an independent loader request, use fetcher.load(url). Use fetcher.submit for POST, PUT, PATCH, or DELETE mutations; its state and action result belong to that fetcher.

JSON handler

Structured submissions use a FormData field containing JSON. Parse them in the route handler, then validate the resulting unknown value before using it. readSubmission also accepts an actual JSON Request when a server client sends one.

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

export async function action({ request }: ActionFunctionArgs) {
  const input = await readSubmission(request);

  return { received: input };
}

Fields

action

action?: string;

encType

encType?: string;

method

method?: string;

replace

replace?: boolean;

preventScrollReset

preventScrollReset?: boolean;
View implementation ↗