Remix
Questi contenuti non sono ancora disponibili nella tua lingua.
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.
@wink/elements npm package Install and load the CDN bundle with TypeScript types.
Install
Section titled “Install”npm install @wink/elementsLoad in app/root.tsx
Section titled “Load in app/root.tsx”useEffect runs only in the browser, never during server-side rendering:
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> );}Environment variables
Section titled “Environment variables”Remix (Vite-based, v2.8+) supports import.meta.env for browser-exposed variables. Prefix with VITE_ to expose to the browser bundle:
VITE_WINK_CLIENT_ID=your-client-idFor older Remix setups using the Node.js adapter, return the client ID from a root loader and read it in the component:
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]);
// ...}Use in routes
Section titled “Use in routes”export default function HotelsRoute() { return ( <main> <wink-content-loader layout="HOTEL" id="YOUR_LAYOUT_ID" /> </main> );}TypeScript types
Section titled “TypeScript types”Add the JSX intrinsic declaration file from the React integration page — Remix uses React under the hood.