HandleDataRequestFunction
A type for an application-owned response transformation.
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 HandleDataRequestFunction = (
response: Response,
args: LoaderFunctionArgs,
) => Response | Promise<Response>;Contract
Accepts a Response and LoaderFunctionArgs, and returns a Response or Promise<Response>. It describes a response transformation rather than the request dispatcher signature.
import type { HandleDataRequestFunction } from "@kasperrt/smolter/preact";
export const addHeader: HandleDataRequestFunction = (response) => {
const headers = new Headers(response.headers);
headers.set("X-Application", "tasks");
return new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers,
});
};Usage and limits
This type does not register a hook by itself. Call your transformation from the application’s server integration. It is not the same as the generated server entry’s handleDataRequest(request) function.