Preact
ממשק ה-API של Preact תואם ל-React. האינטגרציה מתבצעת באותו דפוס — קוראים ל-load() פעם אחת בעת הפעלת האפליקציה, ואז משתמשים בתגי <wink-*> ב-JSX.
@wink/elements npm package התקן וטעין את חבילת ה-CDN עם טיפוסי TypeScript.
npm install @wink/elementsטעינה פעם אחת בעת הפעלת האפליקציה
Section titled “טעינה פעם אחת בעת הפעלת האפליקציה”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 />;}שימוש ב-JSX
Section titled “שימוש ב-JSX”export function HotelsPage() { return ( <main> <wink-content-loader layout="HOTEL" id="YOUR_LAYOUT_ID" /> <wink-lookup /> </main> );}TypeScript — הכרזת JSX intrinsics
Section titled “TypeScript — הכרזת JSX intrinsics”מרחב השמות JSX של Preact נפרד מזה של React. יש להרחיב את 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 עם preact/compat
Section titled “Preact עם preact/compat”אם אתם מגדירים React כ-alias ל-preact/compat, השתמשו בהכרזות JSX של React במקום זאת:
// השתמש בהכרזת JSX של React מ-/integrations/react// — preact/compat מייצא מחדש את מרחב השמות JSX של React