json
Edit this pageReturns JSON data from an action while also providing options for controlling revalidation of cache data on the route.
import { action, json } from "@solidjs/router";import { fetchTodo } from "../fetchers";
const getCompletedTodos = action(async () => { const completedTodos = await fetchTodo({ status: 'complete' });
return json(completedTodos, { revalidate: getTodo.keyFor(id) });});
Also read action and revalidate.
Type Signature
interface ResponseOptions & Omit<ResponseInit, "body"> { revalidate?: string | string[];}
json<T>(data: T, opt?: ResponseOptions): CustomResponse<T>;
The ResponseOptions
extens the types from the native ResponseInit
interface.