Preact
API Preact je združljiv z React. Integracija sledi istemu vzorcu — pokličite load() enkrat ob zagonu aplikacije, nato pa uporabljajte <wink-*> oznake v JSX.
@wink/elements npm package Namestite in naložite CDN paket s tipi za TypeScript.
Namestitev
Section titled “Namestitev”npm install @wink/elementsNaložite enkrat ob zagonu aplikacije
Section titled “Naložite enkrat ob zagonu aplikacije”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 />;}Uporaba v JSX
Section titled “Uporaba v JSX”export function HotelsPage() { return ( <main> <wink-content-loader layout="HOTEL" id="YOUR_LAYOUT_ID" /> <wink-lookup /> </main> );}TypeScript — deklarirajte JSX intrinseke
Section titled “TypeScript — deklarirajte JSX intrinseke”JSX namespace v Preact je ločen od Reactovega. Razširite 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 z preact/compat
Section titled “Preact z preact/compat”Če preusmerjate React na preact/compat, uporabite React JSX deklaracije:
// Uporabite React JSX deklaracijo iz /integrations/react// — preact/compat ponovno izvozi Reactov JSX namespace