Hoppa till innehåll

Next.js

Det här innehållet är inte tillgängligt på ditt språk än.

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.

Terminal window
npm install @wink/elements

Create a client component that calls load() once and render it inside your root layout:

components/WinkLoader.tsx
'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;
}
app/layout.tsx
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:

app/hotels/page.tsx
'use client';
export default function HotelsPage() {
return (
<main>
<wink-content-loader layout="HOTEL" id="YOUR_LAYOUT_ID" />
</main>
);
}

Load once in _app.tsx:

pages/_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:

pages/hotels.tsx
export default function HotelsPage() {
return <wink-content-loader layout="HOTEL" id="YOUR_LAYOUT_ID" />;
}

Add to .env.local:

NEXT_PUBLIC_WINK_CLIENT_ID=your-client-id

NEXT_PUBLIC_ prefix is required to expose the variable to the browser bundle.

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.