Preact
API Preacta je kompatibilan s Reactom. Integracija slijedi isti obrazac — pozovite load() jednom pri pokretanju aplikacije, zatim koristite <wink-*> oznake u JSX-u.
@wink/elements npm paket Instalirajte i učitajte CDN paket s TypeScript tipovima.
Instalacija
Section titled “Instalacija”npm install @wink/elementsUčitajte jednom pri pokretanju aplikacije
Section titled “Učitajte jednom pri pokretanju 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 />;}Korištenje u JSX-u
Section titled “Korištenje u JSX-u”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 u Preactu je odvojen od Reactovog. Proš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 s preact/compat
Section titled “Preact s preact/compat”Ako koristite alias Reacta na preact/compat, koristite React JSX deklaracije:
// Koristite React JSX deklaraciju iz /integrations/react// — preact/compat ponovno izvozi Reactov JSX namespace