コンテンツにスキップ

Preact

PreactのAPIはReactと互換性があります。統合は同じパターンに従います — アプリ起動時に一度だけload()を呼び出し、その後JSX内で<wink-*>タグを使用します。

Terminal window
npm install @wink/elements

アプリ起動時に一度だけ読み込む

Section titled “アプリ起動時に一度だけ読み込む”
src/app.tsx
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 />;
}
src/pages/hotels.tsx
export function HotelsPage() {
return (
<main>
<wink-content-loader layout="HOTEL" id="YOUR_LAYOUT_ID" />
<wink-lookup />
</main>
);
}

TypeScript — JSXの組み込み要素を宣言する

Section titled “TypeScript — JSXの組み込み要素を宣言する”

PreactのJSX名前空間はReactとは別です。preact/src/jsx.d.tsを拡張します:

src/wink-elements.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>;
}
}
}

Reactをpreact/compatにエイリアスしている場合は、ReactのJSX宣言を使用してください:

src/wink-elements.d.ts
// /integrations/reactのReact JSX宣言を使用します
// — preact/compatはReactのJSX名前空間を再エクスポートします