
Set up a React project
This guide uses Next.js but you can apply the instructions to any React project. Create a new Next.js app with thecreate-next-app
command-line tool.
my-react-storefront
and starts a local development server on http://localhost:3000/
.
Build your search experience
To create the search experience, you can either:- Use the Unified InstantSearch package.
- Build a custom experience with React InstantSearch.
Download and run Unified InstantSearch
Clone the Unified InstantSearch GitHub repository.Configure Unified InstantSearch for your data
Open the fileunified-instantsearch-ecommerce/src/config/settings.js
and make the following changes:
-
Add your Algolia application ID, search API key, and index name:
JavaScript
-
Configure your replica indices for sorting by “price” in ascending and descending order:
JavaScript
-
Configure your category attributes.
By default, the Algolia cartridge indexes the primary category on the attributes
__primary_category.*
:JavaScript -
Set your price attribute.
By default, the Algolia cartridge indexes prices on the attributes
price.${currency}
:JavaScript -
Optional: remove query suggestions.
If you don’t have Query Suggestions set up, remove the following code:
JavaScript
-
Customize the Hit component:
TheJSX
<Hit>
component includes code for sending click events when users select a product in the search results.
Export the project
To make your frontend available in your storefront, you need to export it:unified-instantsearch-ecommerce/export
with all assets.
Copy this directory to the public
directory of your storefront project.
Create a new Search component
To use your React frontend in your storefront, create a new Search component in thecomponents
directory.
Search.js
:
JavaScript
Use your Search component in your storefront
Open the filepages/index.js
with your Home component and add your Search component to it.