Skip to content

Remix

Remix je full-stack framework koji po zadanim postavkama renderira na serveru. Učitajte Wink CDN samo na klijentu koristeći useEffect u root komponenti.

Terminal window
npm install @wink/elements

useEffect se izvršava samo u pregledniku, nikada tijekom server-side renderiranja:

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 (baziran na Vite, v2.8+) podržava import.meta.env za varijable izložene pregledniku. Dodajte prefiks VITE_ da ih izložite u browser bundle:

.env
VITE_WINK_CLIENT_ID=your-client-id

Za starije Remix postavke koje koriste Node.js adapter, vratite client ID iz root loadera i pročitajte ga u komponenti:

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>
);
}

Dodajte JSX intrinsic deklaracijsku datoteku s React integracijske stranice — Remix koristi React ispod haube.