> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# configure

> Adds search parameters to your requests.

<div className="not-prose algolia-flavor-switcher">
  <div className="afs-dropdown">
    <div className="afs-trigger" role="button" tabIndex="0" aria-haspopup="listbox">
      <span className="afs-current">JavaScript</span>

      <svg className="afs-chevron lucide lucide-chevron-down" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
        <path d="m6 9 6 6 6-6" />
      </svg>
    </div>

    <ul className="afs-menu" role="listbox">
      <li role="option" aria-selected="true"><a className="afs-option is-current" href="/doc/api-reference/widgets/configure/js"><span className="afs-option-name">JavaScript</span><span className="afs-option-lib">InstantSearch.js</span></a></li>
      <li role="option" aria-selected="false"><a className="afs-option" href="/doc/api-reference/widgets/configure/react"><span className="afs-option-name">React</span><span className="afs-option-lib">React InstantSearch</span></a></li>
      <li role="option" aria-selected="false"><a className="afs-option" href="/doc/api-reference/widgets/configure/vue"><span className="afs-option-name">Vue</span><span className="afs-option-lib">Vue InstantSearch</span></a></li>
      <li role="option" aria-selected="false"><a className="afs-option" href="/doc/api-reference/widgets/configure/ios"><span className="afs-option-name">iOS</span><span className="afs-option-lib">InstantSearch iOS</span></a></li>
      <li role="option" aria-selected="false"><a className="afs-option" href="/doc/api-reference/widgets/configure/android"><span className="afs-option-name">Android</span><span className="afs-option-lib">InstantSearch Android</span></a></li>
      <li role="option" aria-selected="false"><a className="afs-option" href="/doc/api-reference/widgets/configure/flutter"><span className="afs-option-name">Flutter</span><span className="afs-option-lib">Algolia for Flutter</span></a></li>
    </ul>
  </div>
</div>

```ts Signature theme={"system"}
configure(searchParameters: object);
```

## Import

<CodeGroup>
  ```js Package manager theme={"system"}
  import { configure } from "instantsearch.js/es/widgets";
  ```

  ```js CDN theme={"system"}
  const { configure } = instantsearch.widgets;
  // or directly use instantsearch.widgets.configure()
  ```
</CodeGroup>

<Card title="See this widget in action" icon="monitor-play" href="https://instantsearchjs.netlify.app/stories/js/?path=/story/basics-configure--force-1-hit-per-page" horizontal>
  Preview this widget and its behavior.
</Card>

## 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](/doc/api-reference/search-api-parameters).

## Examples

```js JavaScript icon=code theme={"system"}
configure({
  hitsPerPage: 8,
  enablePersonalization: true,
});
```

## Options

<ParamField body="searchParameters" type="object" required>
  A list of [search parameters](/doc/api-reference/search-api-parameters) to enable when the widget mounts.

  ```js JavaScript icon=code theme={"system"}
  configure({
    hitsPerPage: 8,
    distinct: true,
    clickAnalytics: true,
    enablePersonalization: true,
  });
  ```
</ParamField>

## 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.

<CodeGroup>
  ```js Package manager theme={"system"}
  import { connectConfigure } from "instantsearch.js/es/connectors";
  ```

  ```js CDN theme={"system"}
  const { connectConfigure } = instantsearch.connectors;
  // or directly use instantsearch.connectors.connectConfigure()
  ```
</CodeGroup>

Then it's a 3-step process:

```js JavaScript icon=code theme={"system"}
// 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).

```js JavaScript icon=code theme={"system"}
const renderConfigure = (renderOptions, isFirstRender) => {
  const { refine, widgetParams } = renderOptions;

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

  // Render the widget
};
```

#### Rendering options

<ParamField body="refine" type="function">
  Removes the provided `searchParameters` and applies the one provided to the function.

  ```js JavaScript icon=code theme={"system"}
  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);
    }
  };
  ```
</ParamField>

<ParamField body="widgetParams" type="object">
  All original widget options forwarded to the render function.

  ```js JavaScript icon=code theme={"system"}
  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,
      },
    }),
  ]);
  ```
</ParamField>

### 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`.

```js JavaScript icon=code theme={"system"}
const customConfigure = connectConfigure(renderConfigure);

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

#### Instance options

<ParamField body="searchParameters" type="object" required>
  A list of [search parameters](/doc/api-reference/search-api-parameters) to enable when this widget renders.

  ```js JavaScript icon=code theme={"system"}
  customConfigure({
    searchParameters: {
      hitsPerPage: 8,
      distinct: true,
      clickAnalytics: true,
    },
  });
  ```
</ParamField>

### Full example

<CodeGroup>
  ```html HTML theme={"system"}
  <div id="configure"></div>
  ```

  ```js JavaScript theme={"system"}
  // Create the render function
  const renderConfigure = (renderOptions, isFirstRender) => {
    const { refine, widgetParams } = renderOptions;

    if (isFirstRender) {
      const button = document.createElement("button");
      const pre = document.createElement("pre");

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

      widgetParams.container.appendChild(button);
      widgetParams.container.appendChild(pre);
    }

    widgetParams.container.querySelector("button").textContent =
      `Sets "hitsPerPage" to ${
        widgetParams.searchParameters.hitsPerPage === 8 ? 4 : 8
      }`;

    widgetParams.container.querySelector("pre").innerHTML = JSON.stringify(
      widgetParams.searchParameters,
      null,
      2,
    );
  };

  // Create the custom widget
  const customConfigure = connectConfigure(renderConfigure, () => {});

  // Instantiate the custom widget
  search.addWidgets([
    customConfigure({
      container: document.querySelector("#configure"),
      searchParameters: {
        hitsPerPage: 8,
      },
    }),
  ]);
  ```
</CodeGroup>
