Next.js Integration
A complete template for building Internet Computer applications with Next.js and a Rust backend. This example demonstrates how to configure the IC SDK to work seamlessly with Next.js’s server and client components.
Features Demonstrated
Section titled “Features Demonstrated”- Next.js App Router: Modern React architecture.
- Rust Backend: Integrates with a Rust-based canister.
- Local Development: Scripts to run the full stack locally.
- Environment config: Handling
dfxgenerated declarations in Next.js.
Open in StackBlitz Edit and run in your browser
View on GitHub Browse the source code
Setup Guide
Section titled “Setup Guide”1. Install Dependencies
Section titled “1. Install Dependencies”pnpm install2. Start Local Replica & Deploy
Section titled “2. Start Local Replica & Deploy”# Starts replica, deploys backend, and generates declarationspnpm run dfx:startpnpm run deploy3. Start Next.js
Section titled “3. Start Next.js”pnpm run devConfiguration
Section titled “Configuration”The key to getting Next.js to work with IC Reactor is properly configuring the webpack setup in next.config.js to handle WebAssembly and the DFINITY proxy, or simply using the client-side hooks provided by @ic-reactor/react.
This example uses a client-side only approach for simplicity:
"use client"
import { useActorQuery } from "./reactor"
export default function Home() { const { data, isLoading } = useActorQuery({ functionName: "greet", args: ["World"], })
return <main>{isLoading ? "Loading..." : data}</main>}