React
React 19+ heeft eersteklas ondersteuning voor custom elements. React 18 en eerder geeft alleen stringattributen door — gebruik het onderstaande getypeerde helperpatroon om veilig te blijven over versies heen.
@wink/elements npm package Installeer en laad de CDN-bundel met TypeScript-typen.
Installeren
Section titled “Installeren”npm install @wink/elementsEenmalig laden in de app-root
Section titled “Eenmalig laden in de app-root”Roep load() aan in je top-level component. Het is idempotent — veilig om meerdere keren aan te roepen.
import { useEffect } from 'react';import { load } from '@wink/elements';
export default function App() { useEffect(() => { load({ clientId: import.meta.env.VITE_WINK_CLIENT_ID }); }, []);
return <YourRoutes />;}Componenten gebruiken in JSX
Section titled “Componenten gebruiken in JSX”export default function HotelPage() { return ( <main> <wink-content-loader layout="HOTEL" id="YOUR_LAYOUT_ID" /> <wink-lookup /> </main> );}TypeScript — declareer JSX intrinsics
Section titled “TypeScript — declareer JSX intrinsics”React kent standaard geen custom elementnamen. Voeg één keer een declaratiebestand toe om typefouten te voorkomen:
import type { WinkContentLoaderAttributes, WinkLookupAttributes, WinkSearchButtonAttributes, WinkAccountButtonAttributes, WinkItineraryButtonAttributes, WinkShoppingCartButtonAttributes, WinkAppLoaderAttributes,} from '@wink/elements';
declare module 'react' { namespace JSX { interface IntrinsicElements { 'wink-content-loader': WinkContentLoaderAttributes & React.HTMLAttributes<HTMLElement>; 'wink-lookup': WinkLookupAttributes & React.HTMLAttributes<HTMLElement>; 'wink-search-button': WinkSearchButtonAttributes & React.HTMLAttributes<HTMLElement>; 'wink-account-button': WinkAccountButtonAttributes & React.HTMLAttributes<HTMLElement>; 'wink-itinerary-button': WinkItineraryButtonAttributes & React.HTMLAttributes<HTMLElement>; 'wink-shopping-cart-button': WinkShoppingCartButtonAttributes & React.HTMLAttributes<HTMLElement>; 'wink-app-loader': WinkAppLoaderAttributes & React.HTMLAttributes<HTMLElement>; } }}Getypeerde attributen doorgeven (React 18 veilig)
Section titled “Getypeerde attributen doorgeven (React 18 veilig)”import type { WinkContentLoaderAttributes } from '@wink/elements';
const attrs: WinkContentLoaderAttributes = { layout: 'HOTEL', id: 'abc123', sort: 'POPULARITY',};
// Spread werkt in React 19; voor React 18 zijn alle waarden toch stringsexport default function HotelCard() { return <wink-content-loader layout={attrs.layout} id={attrs.id} sort={attrs.sort} />;}