Preact
Preacts API är kompatibel med React. Integrationen följer samma mönster — anropa load() en gång vid appstart, och använd sedan <wink-*>-taggar i JSX.
@wink/elements npm package Installera och ladda CDN-bunten med TypeScript-typer.
Installera
Section titled “Installera”npm install @wink/elementsLadda en gång vid appstart
Section titled “Ladda en gång vid appstart”import { useEffect } from 'preact/hooks';import { load } from '@wink/elements';
export function App() { useEffect(() => { load({ clientId: import.meta.env.VITE_WINK_CLIENT_ID }); }, []);
return <YourRoutes />;}Använd i JSX
Section titled “Använd i JSX”export function HotelsPage() { return ( <main> <wink-content-loader layout="HOTEL" id="YOUR_LAYOUT_ID" /> <wink-lookup /> </main> );}TypeScript — deklarera JSX intrinsics
Section titled “TypeScript — deklarera JSX intrinsics”Preacts JSX-namnrymd är separat från Reacts. Utöka preact/src/jsx.d.ts:
import type { WinkContentLoaderAttributes, WinkLookupAttributes, WinkSearchButtonAttributes, WinkAccountButtonAttributes, WinkItineraryButtonAttributes, WinkShoppingCartButtonAttributes, WinkAppLoaderAttributes,} from '@wink/elements';
declare module 'preact' { namespace JSX { interface IntrinsicElements { 'wink-content-loader': WinkContentLoaderAttributes & preact.JSX.HTMLAttributes<HTMLElement>; 'wink-lookup': WinkLookupAttributes & preact.JSX.HTMLAttributes<HTMLElement>; 'wink-search-button': WinkSearchButtonAttributes & preact.JSX.HTMLAttributes<HTMLElement>; 'wink-account-button': WinkAccountButtonAttributes & preact.JSX.HTMLAttributes<HTMLElement>; 'wink-itinerary-button': WinkItineraryButtonAttributes & preact.JSX.HTMLAttributes<HTMLElement>; 'wink-shopping-cart-button': WinkShoppingCartButtonAttributes & preact.JSX.HTMLAttributes<HTMLElement>; 'wink-app-loader': WinkAppLoaderAttributes & preact.JSX.HTMLAttributes<HTMLElement>; } }}Preact med preact/compat
Section titled “Preact med preact/compat”Om du aliasar React till preact/compat, använd Reacts JSX-deklarationer istället:
// Använd React JSX-deklarationen från /integrations/react// — preact/compat exporterar om Reacts JSX-namnrymd