Preact
Preact API yra suderinama su React. Integracija vykdoma pagal tą patį modelį — vieną kartą iškvieskite load() programos paleidimo metu, tada JSX naudokite <wink-*> žymes.
@wink/elements npm paketas Įdiekite ir įkelkite CDN paketą su TypeScript tipais.
Įdiegimas
Section titled “Įdiegimas”npm install @wink/elementsVieną kartą įkelkite programos paleidimo metu
Section titled “Vieną kartą įkelkite programos paleidimo metu”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 />;}Naudojimas JSX
Section titled “Naudojimas JSX”export function HotelsPage() { return ( <main> <wink-content-loader layout="HOTEL" id="YOUR_LAYOUT_ID" /> <wink-lookup /> </main> );}TypeScript — deklaruokite JSX intrinsics
Section titled “TypeScript — deklaruokite JSX intrinsics”Preact JSX vardų sritis yra atskira nuo React. Papildykite 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 su preact/compat
Section titled “Preact su preact/compat”Jei React pervadinate į preact/compat, naudokite React JSX deklaracijas:
// Naudokite React JSX deklaraciją iš /integrations/react// — preact/compat pereksportuoja React JSX vardų sritį