DataResponse
Typed data accompanied by HTTP status and headers.
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 DataResponse<T> {
value: T;
init: ResponseInit;
__routeData: true;
}Contract
Contains value: T, init: ResponseInit, and the __routeData discriminator. Construct it with data(value, init), rather than constructing the marker object yourself.
import type { DataResponse } from "@kasperrt/smolter/preact";
import { data } from "@kasperrt/smolter/preact";
interface Validation {
name: string;
}
export function invalidName(): DataResponse<Validation> {
return data({ name: "Name is required" }, { status: 422 });
}Usage and limits
RouteData unwraps the value type. Application transport serializes the value; direct resource responses and page action HTML preserve the provided status and headers. Use redirect(...) for navigation, not a DataResponse with a Location header.
Fields
value
value: T;init
init: ResponseInit;__routeData
__routeData: true;