This API is a WIP and is subject to change. To use this API, you can use the following version of the Makeswift runtime: 0.0.0-snapshot-20241113160601

Arguments

  1. id
    string
    required

    The id of the component.

  2. options
    object
    required

    Options for site version and locale.

Return type

snapshot
Promise<MakeswiftComponentSnapshot | null>

An opaque MakeswiftComponentSnapshot object that is only intended to be rendered by the <MakeswiftComponent> component.

Examples

The following examples expect that you have a Makeswift client instance already configured and exported from "@/makeswift/client.ts". If you don’t, see the client reference.

Basic usage

import { getSiteVersion } from "@makeswift/runtime/next/server";
import { Makeswift } from "@makeswift/runtime/next";
import { ReactRuntime } from "@makeswift/runtime/react";

export const runtime = new ReactRuntime();

export const client = new Makeswift(process.env.MAKESWIFT_SITE_API_KEY, {
  runtime,
});

const productDetailSnapshot = await client.getComponentSnapshot(
  `my-product-details`,
  {
    siteVersion: getSiteVersion(),
  }
);

Localization

import { getSiteVersion } from "@makeswift/runtime/next/server";
import { Makeswift } from "@makeswift/runtime/next";
import { ReactRuntime } from "@makeswift/runtime/react";

export const runtime = new ReactRuntime();

export const client = new Makeswift(process.env.MAKESWIFT_SITE_API_KEY, {
  runtime,
});

const locale = "en-US";
const snapshot = await client.getComponentSnapshot(id, {
  siteVersion: getSiteVersion(),
  locale,
});