Guides
React
Never ship a pk_live_ key to the browser. Proxy through your own backend:
// server: /api/posts
import { Pagekit } from "@pagekit/sdk";
const blog = new Pagekit({ apiKey: process.env.PAGEKIT_API_KEY! });
export async function GET() {
const posts = await blog.posts.list({ status: "published" });
return Response.json(posts.data);
}
// client
import { useEffect, useState } from "react";
import type { Post } from "@pagekit/sdk";
export function PostList() {
const [posts, setPosts] = useState<Post[]>([]);
useEffect(() => {
fetch("/api/posts").then((res) => res.json()).then(setPosts);
}, []);
return <ul>{posts.map((post) => <li key={post.id}>{post.title}</li>)}</ul>;
}