Preact
API Preactu je kompatibilné s Reactom. Integrácia nasleduje rovnaký vzor — zavolajte load() raz pri spustení aplikácie, potom používajte značky <wink-*> v JSX.
@wink/elements npm balík Nainštalujte a načítajte CDN balík s typmi pre TypeScript.
Inštalácia
Section titled “Inštalácia”npm install @wink/elementsNačítajte raz pri spustení aplikácie
Section titled “Načítajte raz pri spustení aplikácie”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 />;}Použitie v JSX
Section titled “Použitie v JSX”export function HotelsPage() { return ( <main> <wink-content-loader layout="HOTEL" id="YOUR_LAYOUT_ID" /> <wink-lookup /> </main> );}TypeScript — deklarujte JSX intrinsics
Section titled “TypeScript — deklarujte JSX intrinsics”Namespace JSX v Preact je oddelený od Reactu. Rozšírte 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 s preact/compat
Section titled “Preact s preact/compat”Ak aliasujete React na preact/compat, použite React JSX deklarácie namiesto toho:
// Použite React JSX deklaráciu z /integrations/react// — preact/compat znovu exportuje Reactov namespace JSX