דלגו לתוכן

React

React 19+ תומך באופן מלא ברכיבים מותאמים אישית. React 18 והגרסאות הקודמות מעבירות רק מחרוזות בתור תכונות — השתמשו בתבנית העזר המוטיפית למטה כדי להישאר בטוחים בין הגרסאות.

Terminal window
npm install @wink/elements

טעינה פעם אחת בשורש האפליקציה

Section titled “טעינה פעם אחת בשורש האפליקציה”

קראו ל-load() ברכיב העליון שלכם. הפונקציה אידמפוטנטית — בטוח לקרוא לה מספר פעמים.

src/App.tsx
import { useEffect } from 'react';
import { load } from '@wink/elements';
export default function App() {
useEffect(() => {
load({ clientId: import.meta.env.VITE_WINK_CLIENT_ID });
}, []);
return <YourRoutes />;
}
export default function HotelPage() {
return (
<main>
<wink-content-loader layout="HOTEL" id="YOUR_LAYOUT_ID" />
<wink-lookup />
</main>
);
}

React לא מכיר שמות של רכיבים מותאמים אישית כברירת מחדל. הוסיפו קובץ הכרזה פעם אחת כדי למנוע שגיאות טיפוס:

src/wink-elements.d.ts
import type {
WinkContentLoaderAttributes,
WinkLookupAttributes,
WinkSearchButtonAttributes,
WinkAccountButtonAttributes,
WinkItineraryButtonAttributes,
WinkShoppingCartButtonAttributes,
WinkAppLoaderAttributes,
} from '@wink/elements';
declare module 'react' {
namespace JSX {
interface IntrinsicElements {
'wink-content-loader': WinkContentLoaderAttributes & React.HTMLAttributes<HTMLElement>;
'wink-lookup': WinkLookupAttributes & React.HTMLAttributes<HTMLElement>;
'wink-search-button': WinkSearchButtonAttributes & React.HTMLAttributes<HTMLElement>;
'wink-account-button': WinkAccountButtonAttributes & React.HTMLAttributes<HTMLElement>;
'wink-itinerary-button': WinkItineraryButtonAttributes & React.HTMLAttributes<HTMLElement>;
'wink-shopping-cart-button': WinkShoppingCartButtonAttributes & React.HTMLAttributes<HTMLElement>;
'wink-app-loader': WinkAppLoaderAttributes & React.HTMLAttributes<HTMLElement>;
}
}
}

העברת תכונות מוטיפיות (React 18 בטוח)

Section titled “העברת תכונות מוטיפיות (React 18 בטוח)”
import type { WinkContentLoaderAttributes } from '@wink/elements';
const attrs: WinkContentLoaderAttributes = {
layout: 'HOTEL',
id: 'abc123',
sort: 'POPULARITY',
};
// Spread עובד ב-React 19; ב-React 18 כל הערכים מחרוזות בכל מקרה
export default function HotelCard() {
return <wink-content-loader layout={attrs.layout} id={attrs.id} sort={attrs.sort} />;
}