Server side

Server side functions

Server-side functions for accessing Val content in React Server Components or server-side API routes.

fetchVal

Fetch content from a Val module on the server.

Example

import { fetchVal } from "@/val/val.rsc";
import pageVal from "./page.val";

export default async function Page() {
  const content = await fetchVal(pageVal);
  return <div>{content.title}</div>;
}

fetchValRoute

Fetch content for Val modules that use the .router() method. Takes parameters to resolve the correct route. See page router for more info.

Example

import { fetchValRoute } from "@/val/val.rsc";
import pageVal from "./[slug]/page.val";

export default async function Page({ params }: { params: { slug: string } }) {
  const content = await fetchValRoute(pageVal, params);
  return <div>{content.title}</div>;
}