How to Install React InstantSearch
On this page
We released React InstantSearch Hooks, a new InstantSearch library for React. We recommend using React InstantSearch Hooks in new projects or upgrading from React InstantSearch.
You can use React InstantSearch either with a packaging system or with a direct link in your web page.
With a packaging system
If you have a JavaScript build tool, you can install React InstantSearch from npm:
1
npm install algoliasearch react-instantsearch-dom
Then in your module, you can load the main package:
1
2
3
4
5
6
7
8
9
10
11
import algoliasearch from 'algoliasearch/lite';
import { InstantSearch, SearchBox, Hits } from 'react-instantsearch-dom';
const searchClient = algoliasearch('YourApplicationID', 'YourSearchOnlyAPIKey');
const App = () => (
<InstantSearch searchClient={searchClient} indexName="demo_ecommerce">
<SearchBox />
<Hits />
</InstantSearch>
);
The code examples on this page use the algoliasearch/lite
client, which doesn’t offer indexing methods. If you want to perform indexing operations, you have to import the regular algoliasearch
client.
Directly in your page
This method uses a built version of React InstantSearch from the jsDelivr CDN:
1
2
3
4
<script src="https://cdn.jsdelivr.net/npm/react@18.2.0/umd/react.production.min.js" integrity="sha256-S0lp+k7zWUMk2ixteM6HZvu8L9Eh//OVrt+ZfbCpmgY=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/react-dom@18.2.0/umd/react-dom.production.min.js" integrity="sha256-IXWO0ITNDjfnNXIu5POVfqlgYoop36bDzhodR6LW5Pc=" crossorigin="anonymous"></script>
<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-dom@6.33.0/dist/umd/ReactInstantSearchDOM.min.js" integrity="sha256-VCmBgmgQBT3QsAniaARInmV1076MreRciagm/k09hsE=" crossorigin="anonymous"></script>
The jsDeliver CDN is highly available with over 110 locations in the world.
You now have access to the ReactInstantSearchDOM
object in the global scope (window).
1
2
3
4
5
6
7
8
9
10
const { InstantSearch, SearchBox, Hits } = ReactInstantSearchDOM;
const searchClient = algoliasearch('YourApplicationID', 'YourSearchOnlyAPIKey');
const App = () => (
<InstantSearch searchClient={searchClient} indexName="demo_ecommerce">
<SearchBox />
<Hits />
</InstantSearch>
);
Load the styles
You then need to manually load the companion CSS file into your page:
1
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/instantsearch.css@7.4.5/themes/reset-min.css" integrity="sha256-QlHlZdbSVxaYkUHxhMFhAj/L3pJiW1LuomSCONXBWms=" crossorigin="anonymous">
Or you can load the satellite theme widget styles into your page.
1
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/instantsearch.css@7.4.5/themes/satellite-min.css" integrity="sha256-TehzF/2QvNKhGQrrNpoOb2Ck4iGZ1J/DI4pkd2oUsBc=" crossorigin="anonymous">
You can find more information in the styling guide.
Create InstantSearch App
You can use create-instantsearch-app
. Similarly to other interactive command-line applications, you can run it either with npm
or with yarn
:
1
2
3
npx create-instantsearch-app@latest 'getting-started'
# or
yarn create instantsearch-app 'getting-started'
Supported browsers
The code samples used in this documentation use 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 transform your code into code that works in the browsers you target.
Algolia supports the last two versions of the major browsers: Chrome, Edge, Firefox, Safari.
To support Internet Explorer 11, 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>