🎉 Try the public beta of the new docs site at algolia.com/doc-beta! 🎉
UI libraries / React InstantSearch / Widgets

This is the React InstantSearch v7 documentation. React InstantSearch v7 is the latest version of React InstantSearch and the stable version of React InstantSearch Hooks.

If you were using React InstantSearch v6, you can upgrade to v7.

If you were using React InstantSearch Hooks, you can still use the React InstantSearch v7 documentation, but you should check the upgrade guide for necessary changes.

If you want to keep using React InstantSearch v6, you can find the archived documentation.

Signature
const stateMapping = simple()
Import
1
import { simple } from 'instantsearch.js/es/lib/stateMappings';

About this function

This simple state mapping is the default for the <InstantSearch> component’s routing prop.

The router provides an API that lets you customize some of its behaviors. To get a sense of what you can do with the API, see the Routing URLs guide.

The only transformation applied by the function is the omission of configure.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { simple } from 'instantsearch.js/es/lib/stateMappings';

const stateMapping = simple();

stateMapping.stateToRoute({
  instant_search: {
    query: 'Apple',
    page: 5,
    configure: {
      hitsPerPage: 4,
    },
  },
});

// gives as output:
// {
//   instant_search: {
//     query: 'Apple',
//     page: 5,
//   },
// }

Examples

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { InstantSearch } from 'react-instantsearch';
import { simple } from 'instantsearch.js/es/lib/stateMappings';

const routing = {
  stateMapping: simple(),
};

function App() {
  return (
    <InstantSearch
      searchClient={searchClient}
      indexName="instant_search"
      routing={routing}
    >
      {/* ... */}
    </InstantSearch>
  );
}
Did you find this page helpful?