Next.js
Deze inhoud is nog niet vertaald.
Wink components are browser-only custom elements — CDN scripts must be loaded client-side. The patterns below cover both the App Router (Next.js 13+) and the legacy Pages Router.
@wink/elements npm package Install and load the CDN bundle with TypeScript types.
Install
Section titled “Install”npm install @wink/elementsApp Router (Next.js 13+)
Section titled “App Router (Next.js 13+)”Create a client component that calls load() once and render it inside your root layout:
'use client';import { useEffect } from 'react';import { load } from '@wink/elements';
export function WinkLoader() { useEffect(() => { load({ clientId: process.env.NEXT_PUBLIC_WINK_CLIENT_ID! }); }, []); return null;}import { WinkLoader } from '@/components/WinkLoader';
export default function RootLayout({ children }: { children: React.ReactNode }) { return ( <html lang="en"> <body> <WinkLoader /> {children} </body> </html> );}Use Wink components in any Client Component:
'use client';
export default function HotelsPage() { return ( <main> <wink-content-loader layout="HOTEL" id="YOUR_LAYOUT_ID" /> </main> );}Pages Router
Section titled “Pages Router”Load once in _app.tsx:
import type { AppProps } from 'next/app';import { useEffect } from 'react';import { load } from '@wink/elements';
export default function App({ Component, pageProps }: AppProps) { useEffect(() => { load({ clientId: process.env.NEXT_PUBLIC_WINK_CLIENT_ID! }); }, []); return <Component {...pageProps} />;}Then use Wink components in any page:
export default function HotelsPage() { return <wink-content-loader layout="HOTEL" id="YOUR_LAYOUT_ID" />;}Environment variables
Section titled “Environment variables”Add to .env.local:
NEXT_PUBLIC_WINK_CLIENT_ID=your-client-idNEXT_PUBLIC_ prefix is required to expose the variable to the browser bundle.
TypeScript types
Section titled “TypeScript types”Add a declaration file so TypeScript recognises the custom element names in JSX — see the React integration page for the full wink-elements.d.ts snippet.