React
React 19+ har förstklassigt stöd för custom elements. React 18 och tidigare skickar endast strängattribut — använd det typade hjälpmönstret nedan för att vara säker över versioner.
@wink/elements npm package Installera och ladda CDN-bunten med TypeScript-typer.
Installera
Section titled “Installera”npm install @wink/elementsLadda en gång i appens rot
Section titled “Ladda en gång i appens rot”Anropa load() i din toppnivåkomponent. Den är idempotent — säker att anropa flera gånger.
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 />;}Använd komponenter i JSX
Section titled “Använd komponenter i JSX”export default function HotelPage() { return ( <main> <wink-content-loader layout="HOTEL" id="YOUR_LAYOUT_ID" /> <wink-lookup /> </main> );}TypeScript — deklarera JSX intrinsics
Section titled “TypeScript — deklarera JSX intrinsics”React känner inte till custom element-namn som standard. Lägg till en deklarationsfil en gång för att tysta type-fel:
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>; } }}Skicka typade attribut (React 18-säkert)
Section titled “Skicka typade attribut (React 18-säkert)”import type { WinkContentLoaderAttributes } from '@wink/elements';
const attrs: WinkContentLoaderAttributes = { layout: 'HOTEL', id: 'abc123', sort: 'POPULARITY',};
// Spread fungerar i React 19; för React 18 är alla värden strängar ändåexport default function HotelCard() { return <wink-content-loader layout={attrs.layout} id={attrs.id} sort={attrs.sort} />;}