No Preview

Sorry, but you either have no stories or none are selected somehow.

If the problem persists, check the browser console, or the terminal you've run Storybook from.

Widgets Provider

The WidgetsProvider is the root provider for building a React application with Sitecore Discover platform. It allows to use the SDK hooks in the inner components.

Importing

import { WidgetsProvider } from '@sitecore-search/react';

Usage

It must wrap any components where you are using hooks.

Without subdomain setup

import { WidgetsProvider } from '@sitecore-search/react'; const Root = () => { return ( <WidgetsProvider env='<environment>' customerKey='<customer key>' apiKey='<API key provided in CEC>' > <MyApp /> </WidgetsProvider> )};

Note: In this method, Sitecore Discover needs a way to recognize who is calling the API and that's done through the access token. Warning: this method may lead to security vulnerabilities for that we are exposing the access token in the web page. We don't recommend using this approach on production environments.

With subdomain setup

import { WidgetsProvider } from '@sitecore-search/react'; const Root = () => { return ( <WidgetsProvider env='<environment>' customerKey='<customer_key>' serviceHost='<domain provided in CEC>' > <MyApp /> </WidgetsProvider> )};

Note: This approach does not require an access token for authentication because Sitecore Discover guarantees that the origin of all requests are from the customer's website.

Props

The WidgetsProvider exported by the @sitecore-search/react package accepts the following props.

NameDescriptionType
envEnvironment from where the data should be gathered. Posible values: apse2 (for Asia/Oceania domains), prodEu (for European domains), or prod (for US domains).string
apiKeyAPI key generated by Discover. Required for no subdomain setup.string
customerKeyCustomer ID provided by Discover.string
serviceHostAPI host provided by Discover. Required for subdomain setup.string
pubicSuffixGets the domain to be used to register SDK cookies. if publicSuffix is false (default value) will return only the subdomain to have a cross subdomain cookie. Otherwise, with publicSuffix = true, the full domain will be gathered meaning that cross subdomain cookies are not allowed in this case.
e.g:
- public suffix false, domain = donatello-delta.vercel.app => vercel.app
- public suffix true, domain = donatello-delta.vercel.app => donatello-delta.vercel.app
boolean