Preact
Preact API je kompatibilan sa React-om. Integracija prati isti obrazac — pozovite load() jednom pri pokretanju aplikacije, zatim koristite <wink-*> tagove u JSX-u.
@wink/elements npm paket Instalirajte i učitajte CDN paket sa 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 />;}Koristite u JSX-u
Section titled “Koristite u JSX-u”export function HotelsPage() { return ( <main> <wink-content-loader layout="HOTEL" id="YOUR_LAYOUT_ID" /> <wink-lookup /> </main> );}TypeScript — deklarisanje JSX intrinzičnih elemenata
Section titled “TypeScript — deklarisanje JSX intrinzičnih elemenata”Preact-ov JSX namespace je odvojen od React-ovog. Dopunite 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 sa preact/compat
Section titled “Preact sa preact/compat”Ako koristite alias React-a na preact/compat, koristite React JSX deklaracije umesto:
// Koristite React JSX deklaraciju iz /integrations/react// — preact/compat ponovo izvezi React-ov JSX namespace