How to Install React InstantSearch Hooks
On this page
You can either install React InstantSearch Hooks as an npm package, or include it in your app with a CDN link.
React InstantSearch Hooks is composed of three separate packages:
react-instantsearch-hooks
which exposes all Hooksreact-instantsearch-hooks-web
which exposes all UI widgets and re-exports all Hooksreact-instantsearch-hooks-server
which exposes the server APIs
The code examples on this page use the React InstantSearch Hooks library together with the algoliasearch/lite
client, which is smaller but doesn’t support indexing your data. To perform indexing operations, import the regular algoliasearch
client.
Installing React InstantSearch Hooks as an npm package
If you’re using a package manager and a build tool, you can install React InstantSearch Hooks from npm:
1
2
3
npm install algoliasearch react-instantsearch-hooks-web
# or
yarn add algoliasearch react-instantsearch-hooks-web
Then in your app, import the module:
1
2
3
4
5
6
7
8
9
10
11
12
13
import React from 'react';
import algoliasearch from 'algoliasearch/lite';
import { InstantSearch } from 'react-instantsearch-hooks-web';
const searchClient = algoliasearch('YourApplicationID', 'YourSearchOnlyAPIKey');
function App() {
return (
<InstantSearch searchClient={searchClient} indexName="instant_search">
{/* Widgets */}
</InstantSearch>
);
}
Include React InstantSearch Hooks with a CDN
If you don’t use a package manager and a build tool, you can include React InstantSearch Hooks directly from the jsDelivr CDN.
1
2
3
4
5
6
7
8
9
10
<script
src="https://cdn.jsdelivr.net/npm/algoliasearch@4.14.2/dist/algoliasearch-lite.umd.js"
integrity="sha256-dImjLPUsG/6p3+i7gVKBiDM8EemJAhQ0VvkRK2pVsQY="
crossorigin="anonymous"
></script>
<script
src="https://cdn.jsdelivr.net/npm/react-instantsearch-hooks@6.33.0/dist/umd/ReactInstantSearchHooks.min.js"
integrity="sha256-BOG6peclqcBPfXR7CpIhTjQTsI5UmeFfMa0wu5jmQhw="
crossorigin="anonymous"
></script>
jsDelivr is a third-party CDN. We are not able to provide support regarding third party services.
You now have access to the ReactInstantSearchHooks
object on the global window
object.
1
2
3
4
5
6
7
8
9
10
11
const { InstantSearch } = ReactInstantSearchHooks;
const searchClient = algoliasearch('YourApplicationID', 'YourSearchOnlyAPIKey');
function App() {
return (
<InstantSearch searchClient={searchClient} indexName="instant_search">
{/* Widgets */}
</InstantSearch>
);
}
Browser support
Algolia supports the last two versions of the major browsers: Chrome, Edge, Firefox, Safari.
To support Internet Explorer 11, you can use polyfill.io. Add this script to your page to conditionally load polyfills.
1
<script src="https://polyfill.io/v3/polyfill.min.js?features=default%2CArray.prototype.find%2CArray.prototype.includes%2CPromise%2CObject.assign%2CObject.entries"></script>
The code samples in this documentation use a JavaScript syntax not natively supported by older browsers like Internet Explorer 11. If your site needs to support older browsers, make sure to use a tool like Babel to make your code work in the browsers you target.