diff --git a/.gitignore b/.gitignore index 388d50c..00885de 100644 --- a/.gitignore +++ b/.gitignore @@ -152,3 +152,5 @@ tsup.config.bundled_*.mjs # Claude Code .claude/ + +__snapshots__/ \ No newline at end of file diff --git a/README.md b/README.md index 0e941e6..0febf53 100644 --- a/README.md +++ b/README.md @@ -216,6 +216,14 @@ For the full API reference, component props, design patterns, and common mistake | [`@unlayer-internal/shared-elements`](./packages/shared) | Framework-agnostic shared logic | Internal | | [`@unlayer/elements-demo`](./packages/demo) | Demo application | — | +## Examples + +Runnable projects you can clone and experiment with: + +| Example | Description | +|---------|-------------| +| [`examples/nextjs-app-router`](./examples/nextjs-app-router) | Next.js 15 App Router — renders an email with `renderToHtml()` in a Server Component, previews it at `/email-preview`, and serves the raw HTML from a Route Handler | + ## Development ```bash diff --git a/examples/nextjs-app-router/.gitignore b/examples/nextjs-app-router/.gitignore new file mode 100644 index 0000000..c3a54e7 --- /dev/null +++ b/examples/nextjs-app-router/.gitignore @@ -0,0 +1,4 @@ +node_modules/ +.next/ +package-lock.json +tsconfig.tsbuildinfo diff --git a/examples/nextjs-app-router/README.md b/examples/nextjs-app-router/README.md new file mode 100644 index 0000000..1962331 --- /dev/null +++ b/examples/nextjs-app-router/README.md @@ -0,0 +1,90 @@ +# Next.js App Router example + +Renders an Unlayer Elements email to HTML inside a Next.js 15 App Router +**Server Component**, then previews it in the browser. + +## Run it + +```bash +cd examples/nextjs-app-router +pnpm install +pnpm dev +``` + +Then open: + +- — the email rendered in a preview frame +- — the exact HTML string, served as `text/html` + +This example is self-contained: it installs `@unlayer/react-elements` from npm +like any other app, so nothing in the monorepo needs to be built first. Copy the +directory anywhere and it still runs. + +## What it shows + +| File | Shows | +|------|-------| +| `src/emails/welcome-email.tsx` | A realistic transactional email as a plain component tree, parameterised by props | +| `src/app/email-preview/page.tsx` | A Server Component calling `renderToHtml()` and `renderToPlainText()`, previewing the result in an iframe | +| `src/app/email-preview/raw/route.tsx` | A Route Handler returning the rendered HTML — the shape production code usually takes | + +The key point is what is **absent**: no `"use client"`, no `useEffect`, no +client-side rendering library. `renderToHtml()` runs during the server render +and only the resulting string reaches the browser. + +```tsx +// src/app/email-preview/page.tsx — Server Component +import { renderToHtml } from "@unlayer/react-elements"; +import WelcomeEmail from "@/emails/welcome-email"; + +export default function EmailPreviewPage() { + const html = renderToHtml(, { + title: "Welcome, Ada", + }); + + return