Response Helpers

json

Edit this page

Returns JSON data from an action while also providing options for controlling revalidation of cache data on the route.

/actions/get-completed-todos.ts
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.

Report an issue with this page