Skip to main content
Signature
configure(searchParameters: object);

Import

import { configure } from "instantsearch.js/es/widgets";

About this widget

The configure widget lets you provide raw search parameters to the Algolia API without rendering anything. Any props you add to this widget is forwarded to Algolia. For more information about the different parameters you can set, see the search parameters API reference.

Examples

JavaScript
configure({
  hitsPerPage: 8,
  enablePersonalization: true,
});

Options

searchParameters
object
required
A list of search parameters to enable when the widget mounts.
JavaScript
configure({
  hitsPerPage: 8,
  distinct: true,
  clickAnalytics: true,
  enablePersonalization: true,
});

HTML output

This widget doesn’t have any HTML output.

Customize the UI with connectConfigure

If you want to create your own UI of the configure widget, you can use connectors. To use connectConfigure, you can import it with the declaration relevant to how you installed InstantSearch.js.
import { connectConfigure } from "instantsearch.js/es/connectors";
Then it’s a 3-step process:
JavaScript
// 1. Create a render function
const renderConfigure = (renderOptions, isFirstRender) => {
  // Rendering logic
};

// 2. Create the custom widget
const customConfigure = connectConfigure(renderConfigure);

// 3. Instantiate
search.addWidgets([
  customConfigure({
    // instance params
  }),
]);

Create a render function

This rendering function is called before the first search (init lifecycle step) and each time results come back from Algolia (render lifecycle step).
JavaScript
const renderConfigure = (renderOptions, isFirstRender) => {
  const { refine, widgetParams } = renderOptions;

  if (isFirstRender) {
    // Do some initial rendering and bind events
  }

  // Render the widget
};

Rendering options

refine
function
Removes the provided searchParameters and applies the one provided to the function.
JavaScript
const renderConfigure = (renderOptions, isFirstRender) => {
  const { refine } = renderOptions;

  if (isFirstRender) {
    const button = document.createElement("button");
    button.textContent = 'Sets "hitsPerPage" to 4';

    button.addEventListener("click", () => {
      refine({ hitsPerPage: 4 });
    });

    document.querySelector("#configure").appendChild(button);
  }
};
widgetParams
object
All original widget options forwarded to the render function.
JavaScript
const renderConfigure = (renderOptions, isFirstRender) => {
  const { widgetParams } = renderOptions;

  widgetParams.container.innerHTML = `
    <pre>${JSON.stringify(widgetParams.searchParameters, null, 2)}</pre>
  `;
};

// ...

search.addWidgets([
  customConfigure({
    container: document.querySelector("#configure"),
    searchParameters: {
      hitsPerPage: 8,
    },
  }),
]);

Create and instantiate the custom widget

First, create your custom widgets using a rendering function. Then, instantiate them with parameters. There are two kinds of parameters you can pass:
  • Instance parameters. Predefined options that configure Algolia’s behavior.
  • Custom parameters. Parameters you define to make the widget reusable and adaptable.
Inside the renderFunction, both instance and custom parameters are accessible through connector.widgetParams.
JavaScript
const customConfigure = connectConfigure(renderConfigure);

search.addWidgets([customConfigure({ searchParameters: {} })]);

Instance options

searchParameters
object
required
A list of search parameters to enable when this widget renders.
JavaScript
customConfigure({
  searchParameters: {
    hitsPerPage: 8,
    distinct: true,
    clickAnalytics: true,
  },
});

Full example

<div id="configure"></div>
I