Preact
PreactのAPIはReactと互換性があります。統合は同じパターンに従います — アプリ起動時に一度だけload()を呼び出し、その後JSX内で<wink-*>タグを使用します。
@wink/elements npm package TypeScriptの型定義付きでCDNバンドルをインストールして読み込みます。
インストール
Section titled “インストール”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の組み込み要素を宣言する
Section titled “TypeScript — JSXの組み込み要素を宣言する”PreactのJSX名前空間は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/compatを使う場合
Section titled “preact/compatを使う場合”Reactをpreact/compatにエイリアスしている場合は、ReactのJSX宣言を使用してください:
// /integrations/reactのReact JSX宣言を使用します// — preact/compatはReactのJSX名前空間を再エクスポートします