Preact
Preacts API er kompatibel med React. Integrasjonen følger samme mønster — kall load() én gang ved app-start, og bruk deretter <wink-*>-tagger i JSX.
@wink/elements npm package Installer og last inn CDN-bunten med TypeScript-typer.
Installer
Section titled “Installer”npm install @wink/elementsLast inn én gang ved app-start
Section titled “Last inn én gang ved app-start”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 />;}Bruk i JSX
Section titled “Bruk i JSX”export function HotelsPage() { return ( <main> <wink-content-loader layout="HOTEL" id="YOUR_LAYOUT_ID" /> <wink-lookup /> </main> );}TypeScript — deklarer JSX intrinsics
Section titled “TypeScript — deklarer JSX intrinsics”Preacts JSX-namespace er separat fra React sin. Utvid 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”Hvis du aliaser React til preact/compat, bruk React sine JSX-deklarasjoner i stedet:
// Bruk React JSX-deklarasjonen fra /integrations/react// — preact/compat re-eksporterer React sin JSX-namespace