react-server675fbba4
react-serverfilesexamplestyped-file-routerpages(server).todos.resource.ts
examples/typed-file-router/pages/(server).todos.resource.tsts686 Bbaf470d7
/**
 * Server-side todos resource.
 *
 * Exports: key (schema), loader (data fetcher), mapping (route → key).
 *
 * "use cache: request" caches the result for the current request.
 * The data is hydrated to the client on initial page load.
 * On client-side navigation, the client resource takes over.
 */
import { todos } from "@lazarv/react-server/routes";
import { loadTodos } from "../src/todos-loader";

export const key = { filter: String };

export const loader = async ({ filter }: { filter: string }) => {
  "use cache: request";
  return loadTodos({ filter });
};

export const mapping = todos.createResourceMapping(({ search }) => ({
  filter: search.filter ?? "all",
}));