Add Algolia enhancer

Before your front-end application can interpret the Algolia parameter values returned from Canvas, you must complete this one-time activation of Algolia enhancers into your app.

If you aren't familiar with the concept of enhancers, please check out this section about enhancers. To start with a pre-configured Next.js app already wired up to an Algolia enhancer, please use the following example:

  1. Add the following npm packages to your front-end application:

  2. In a text editor, open the file where you retrieve the composition definition from Uniform.

    You are looking for the code calls the async function getComposition. The code below assumes the object returned is set in a variable composition.

  3. Add the following import statements:

  4. Add the following code:

    About this step

    We recommend moving the Algolia credentials to environment variables rather than hard coding them in the front-end app.

  5. Add the following code:

  6. Add the following code before your return your composition:


That's it! Your app is able to enhance both Algolia parameter values and return real data from the Algolia index. Your components now should receive the expected data from Algolia.