Skip to main content

React

The GuideContent widget lets you render the content of a guide on your website.

Installation

The Algolia Guides React package is available on the npm registry.
npm install @algolia/generative-experiences-react

Usage

React
import { createClient } from "@algolia/generative-experiences-api-client";
import { GuideContent } from "@algolia/generative-experiences-react";

const client = createClient({
  appId: "ALGOLIA_APPLICATION_ID",
  indexName: "your_index_name",
  searchOnlyAPIKey: "ALGOLIA_SEARCH_API_KEY",
  region: "us",
});

function App({ userToken, currentObjectID }) {
  //...

  return (
    <GuideContent
      client={client}
      showFeedback
      userToken={userToken}
      objectID={currentObjectID}
      itemComponent={({ hit }) => <HitComponent hit={hit} />}
    />
  );
}

Parameters

client
GSEClient
required
The initialized Algolia Generative Experiences client.
objectID
string
required
The ID of the guide to be retrieved.
itemComponent
({ item, createElement, Fragment, html }) => JSX.Element | VNode | VNode[]
required
Component to display the items featured in the guide.
onlyPublished
boolean
default:true
Whether to only return headlines with generated content.
showImmediate
boolean
default:true
Whether to generate and display the headlines on load.
The title of the related items carousel found at the end of a guide. Default: Items featured in this article
The number of featured items displayed at the end of a guide.
showFeedback
boolean
default:false
Whether to show the feedback widget. If true, you also need to provide a userToken.
userToken
string
The user token needed for computing feedback. Required if showFeedback is true.
children
(props: ChildrenProps) => JSX.Element
A render function to fully customize what’s displayed.The default implementation is:
React
function defaultRender(props) {
  return (
    <section
      className={cx("ais-GuidesContent-wrapper", props.classNames?.wrapper)}
    >
      <props.View />
    </section>
  );
}
view
ViewProps
The view component into which your guide content will be rendered.
classNames
ContentClassNames
The class names for the component.
TypeScript
type ContentClassNames = Partial<{
  wrapper?: string;
  container?: string;
  errorContainer?: string;
  errorContainerTitle?: string;
  contentSection?: string;
  productLink?: string;
  heroImage?: string;
  introSection?: string;
  articleContentSection?: string;
  factorsSection?: string;
  factorsList?: string;
  factorItem?: string;
  productSection?: string;
  productFactorsList?: string;
  relatedItemsSection?: string;
  relatedItemsListContainer?: string;
  relatedItemsTitle?: string;
  relatedItemsList?: string;
  item?: string;
}>;

JavaScript

The guideContent widget lets you reference and render different guides on your website.

Installation

The Algolia Guides JavaScript package is available on the npm registry.
npm install @algolia/generative-experiences-js

Usage

JavaScript
import { createClient } from "@algolia/generative-experiences-api-client";
import { guideContent } from "@algolia/generative-experiences-js";

const client = createClient({
  appId: "ALGOLIA_APPLICATION_ID",
  indexName: "your_index_name",
  searchOnlyAPIKey: "ALGOLIA_SEARCH_API_KEY",
  region: "us",
});

guideContent({
  container: "#content",
  client: client,
  userToken: "test-user",
  showFeedback: true,
  itemComponent({ hit }) {
    return <div>{hit.title}</div>;
  },
  objectID: objectID,
});

Parameters

client
GSEClient
required
The initialized Algolia Generative Experiences client.
objectID
string
required
The ID for the guide to be retrieved.
itemComponent
({ item, createElement, Fragment, html }) => JSX.Element | VNode | VNode[]
required
Component to display the items featured in the guide.
onlyPublished
boolean
default:true
Whether to only return headlines with generated content.
showImmediate
boolean
default:true
Whether to generate and display the headlines on load.
The title of the related items carousel found at the end of a guide. Default: Items featured in this article
The number of featured items displayed at the end of a guide.
showFeedback
boolean
default:false
Whether to show the feedback widget. If true, you also need to provide a userToken.
userToken
string
The user token needed for computing feedback. Required if showFeedback is true
children
(props: ChildrenProps) => JSX.Element
A render function to fully customize what’s displayed.The default implementation is:
JavaScript
function defaultRender(props) {
  return (
    <section
      className={cx("ais-GuidesContent-wrapper", props.classNames?.wrapper)}
    >
      <props.View />
    </section>
  );
}
view
ViewProps
The view component into which your guide content will be rendered.
classNames
ContentClassNames
The Class names for the component.
TypeScript
type ContentClassNames = Partial<{
  wrapper?: string;
  container?: string;
  errorContainer?: string;
  errorContainerTitle?: string;
  contentSection?: string;
  productLink?: string;
  heroImage?: string;
  introSection?: string;
  articleContentSection?: string;
  factorsSection?: string;
  factorsList?: string;
  factorItem?: string;
  productSection?: string;
  productFactorsList?: string;
  relatedItemsSection?: string;
  relatedItemsListContainer?: string;
  relatedItemsTitle?: string;
  relatedItemsList?: string;
  item?: string;
}>;
I