Pāriet uz saturu

Gatsby

Šis saturs vēl nav pieejams jūsu valodā.

Gatsby generates static HTML at build time and rehydrates on the client. CDN scripts must be loaded in browser APIs only — gatsby-browser.js is the right place.

Terminal window
npm install @wink/elements

The onClientEntry API runs once as soon as Gatsby’s runtime initialises in the browser:

gatsby-browser.js
import { load } from '@wink/elements';
export function onClientEntry() {
load({ clientId: process.env.GATSBY_WINK_CLIENT_ID });
}

Gatsby exposes only variables prefixed with GATSBY_ to the browser bundle:

.env.production
GATSBY_WINK_CLIENT_ID=your-client-id
.env.development
GATSBY_WINK_CLIENT_ID=your-client-id
src/pages/hotels.tsx
import React from 'react';
export default function HotelsPage() {
return (
<main>
<wink-content-loader layout="HOTEL" id="YOUR_LAYOUT_ID" />
<wink-lookup />
</main>
);
}

Gatsby uses React, so add the same JSX intrinsic declarations as the React integration:

src/wink-elements.d.ts
// See /integrations/react for the full declaration file

You do not need to modify gatsby-ssr.js. The <wink-*> tags render as plain HTML elements in the static output, and the CDN script upgrades them when the browser loads the page.