Next.js (App Router)
ActiveServer Components + client AddressFinder, validation in a Server Action.
SET UP
Install
Client widget
npm i @postio/react @tanstack/react-queryServer validation
npm i @postio/nodeEXAMPLE
30-second example
tsx
// app/checkout/page.tsx 'use client'; import { PostioProvider, AddressFinder } from '@postio/react'; export default function CheckoutPage() { return ( <PostioProvider apiKey={process.env.NEXT_PUBLIC_POSTIO_KEY!}> <AddressFinder onSelect={(addr) => console.log(addr)} placeholder="Start typing an address…" /> </PostioProvider> ); } // app/checkout/actions.ts 'use server'; import { Postio } from '@postio/node'; const postio = new Postio({ apiKey: process.env.POSTIO_API_KEY! }); export async function validatePostcode(postcode: string) { const { results } = await postio.address.postcode(postcode); return results; }
RELATED