Siirry sisältöön

Remix

Tämä sisältö ei ole vielä saatavilla valitsemallasi kielellä.

Remix is a full-stack framework that server-renders by default. Load the Wink CDN only on the client using useEffect in the root component.

Terminal window
npm install @wink/elements

useEffect runs only in the browser, never during server-side rendering:

app/root.tsx
import { useEffect } from 'react';
import {
Links, Meta, Outlet, Scripts, ScrollRestoration,
} from '@remix-run/react';
import { load } from '@wink/elements';
export default function App() {
useEffect(() => {
load({ clientId: import.meta.env.VITE_WINK_CLIENT_ID });
}, []);
return (
<html lang="en">
<head>
<Meta />
<Links />
</head>
<body>
<Outlet />
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}

Remix (Vite-based, v2.8+) supports import.meta.env for browser-exposed variables. Prefix with VITE_ to expose to the browser bundle:

.env
VITE_WINK_CLIENT_ID=your-client-id

For older Remix setups using the Node.js adapter, return the client ID from a root loader and read it in the component:

app/root.tsx
import { json } from '@remix-run/node';
import { useLoaderData } from '@remix-run/react';
export async function loader() {
return json({ winkClientId: process.env.WINK_CLIENT_ID });
}
export default function App() {
const { winkClientId } = useLoaderData<typeof loader>();
useEffect(() => {
if (winkClientId) {
load({ clientId: winkClientId });
}
}, [winkClientId]);
// ...
}
app/routes/hotels.tsx
export default function HotelsRoute() {
return (
<main>
<wink-content-loader layout="HOTEL" id="YOUR_LAYOUT_ID" />
</main>
);
}

Add the JSX intrinsic declaration file from the React integration page — Remix uses React under the hood.