blog database with a
published checkbox. Replace names with those in your generated schema.
Use the generated client
notcms init creates the schema and exports nc. Next.js loads .env.local
on the server, so import that client from your server component or server-only
helper. Do not import it into a component marked "use client".
If you create a client yourself, pass schema to new Client({ schema });
credentials alone cannot define the typed queries.
Fetch a public list
Call a helper like this from an async server component. Adjust the relative import to the location of your generated schema:post.title and link to /blog/${post.id}. Properties you defined in
Notion are under post.properties; the page title and ID are top-level fields.
Throwing a query error allows a Next.js error boundary to handle service failures
instead of displaying an empty successful list.
Fetch a detail page
A property lookup can apply the publication rule while retrieving the body:app/blog/[id]/page.tsx, await params to read the ID, call this helper, and
call Next.js notFound() only when the result is null. Service errors should
remain errors. getFirst reads synchronized content, so a change in Notion
becomes visible after the next sync. See single-page queries
for the differences from get(id).
The Markdown body is post.content, not post.properties.content. Render it
with a Markdown renderer appropriate for your content’s trust level. If HTML is
allowed, sanitize untrusted HTML before inserting it into the page.
Choose a publication and refresh policy
For scheduled dates, language fallback, and separate list/detail checks, use the tested content recipes. That guide includes Next.js route examples with asynchronousparams. The reusable query and
publication code lives in
examples/content-recipes
and is covered by SDK tests.
After Notion synchronization, refresh any application cache you configured.
A statically built deployment needs a rebuild to include edits or remove an
unpublished page. Choose that behavior for your application explicitly; an SDK
request does not invalidate Next.js caches or trigger deployments.