Walkthrough: Setting up the React project

This walkthrough is the part one of the Rapid development using UI components walkthrough series.

You will learn how to:

  • Install JS SDK and UI Components for React.

  • Retrieve credentials.

  • Authenticate with credentials.

Install JS SDK and UI Components for React

Developers can install Sitecore Search JS SDK and UI Components packages into their projects. In your React code, you can import classes, functions, and objects from these packages, just as you would from other JS packages.

To install the latest JS SDK and UI Components for React:

  1. To add Search JS SDK for React to your project, run the following in your project:

    RequestResponsejs
    npm install --save @sitecore-search/react
  2. To add Search UI Components for React to your project, run the following in your project:

    RequestResponsejs
    npm install --save @sitecore-search/ui
  3. In the Root component of your React project, import the WidgetsProvider component as shown in the following:

    RequestResponsejs
    import { WidgetsProvider } from "@sitecore-search/react";
    
    const Root = () => {
        return (
            <WidgetsProvider>
            </WidgetsProvider>
    )};

Retrieve credentials

To protect your privacy and content, we require that your application authenticate with Search before making any requests. You need to use the credentials associated with your account and domain.

To retrieve your Search credentials:

  1. Log in to the Customer Engagement Console (CEC) with your personal credentials.

  2. On the menu bar, click Developer Resources.

  3. In the API Keys pane on the right, copy the key for data requests.

Authenticate with credentials

To protect your privacy and content, we require that your application authenticate with Search before making any requests. You need to use the credentials associated with your account and domain. You can choose to authenticate before you make any data requests or along with your fist data request.

After the JS SDK successfully authenticates the application, the JS SDK includes the necessary authentication information in all future requests.

We recommend you include the credentials in the Root or App component of your React application.

To authenticate when your subdomain is set up:

  • In the Root component of your React project, add the WidgetsProvider component with the correct credentials for authentication, as shown in the following code block.

    RequestResponsejs
    import { WidgetsProvider } from "@sitecore-search/react";
    
    const Root = () => {
        return (
            <WidgetsProvider
                    env='<environment>'
                    customerKey='<customer key>'
                    apiDomain='<api domain>'
                >
                <MyApp />
            </WidgetsProvider>
    )};
Note

Credentials depend on how your domain is set up with Sitecore. For instructions on authenticating when your subdomain is not set up with Search, refer to Authenticate without domain set up.

Do you have some feedback for us?

If you have suggestions for improving this article,