@schemacompany/next
v0.1.1
Published
Next.js SDK for The Schema Company
Readme
@schemacompany/next
Next.js SDK for The Schema Company. Supports both App Router (Server Components) and Pages Router.
Installation
npm install @schemacompany/nextApp Router Usage
SchemaScript Component
Use the SchemaScript async server component to automatically fetch and inject schemas:
// app/page.tsx
import { SchemaScript } from "@schemacompany/next";
export default function Page() {
return (
<>
<SchemaScript hash="your-64-char-hash..." />
<main>Your page content</main>
</>
);
}fetchSchema Helper
For use in generateMetadata or other server contexts:
import { fetchSchema } from "@schemacompany/next";
export async function generateMetadata() {
const schema = await fetchSchema("your-hash...");
// Use schema data for metadata
}Pages Router Usage
getStaticSchema / getSchema
// pages/index.tsx
import { getStaticSchema, SchemaHead } from "@schemacompany/next";
import Head from "next/head";
export async function getStaticProps() {
const { schema, revalidate } = await getStaticSchema({ hash: "your-hash..." });
return { props: { schema }, revalidate };
}
export default function Page({ schema }) {
return (
<>
<Head>
<SchemaHead schema={schema} />
</Head>
<main>Your content</main>
</>
);
}For SSR, use getSchema instead:
export async function getServerSideProps() {
const schema = await getSchema({ hash: "your-hash..." });
return { props: { schema } };
}API
App Router
SchemaScript({ hash, baseUrl? })- Server component that fetches and renders the schemafetchSchema(hash, baseUrl?)- Async function to fetch schema data
Pages Router
getSchema({ hash, baseUrl? })- Fetch schema for SSRgetStaticSchema({ hash, baseUrl? })- Fetch schema for SSG with revalidationSchemaHead({ schema })- Component to render schema in<Head>
Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| hash | string | required | 64-character hex hash |
| baseUrl | string | Production URL | Override API base URL |
License
MIT
