Preact
API Preact jest kompatybilne z React. Integracja przebiega według tego samego wzorca — wywołaj load() raz przy uruchomieniu aplikacji, a następnie używaj tagów <wink-*> w JSX.
@wink/elements npm package Zainstaluj i załaduj pakiet CDN z typami TypeScript.
Instalacja
Dział zatytułowany „Instalacja”npm install @wink/elementsZaładuj raz przy uruchomieniu aplikacji
Dział zatytułowany „Załaduj raz przy uruchomieniu aplikacji”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 />;}Użycie w JSX
Dział zatytułowany „Użycie w JSX”export function HotelsPage() { return ( <main> <wink-content-loader layout="HOTEL" id="YOUR_LAYOUT_ID" /> <wink-lookup /> </main> );}TypeScript — deklaracja JSX intrinsics
Dział zatytułowany „TypeScript — deklaracja JSX intrinsics”Namespace JSX w Preact jest oddzielny od React. Rozszerz 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
Dział zatytułowany „Preact z preact/compat”Jeśli aliasujesz React na preact/compat, użyj deklaracji JSX Reacta:
// Użyj deklaracji JSX React z /integrations/react// — preact/compat eksportuje namespace JSX Reacta