Registry / http-networking / react-instantsearch-core

react-instantsearch-core

JSON →
library7.29.0jsnpmunverified

React InstantSearch Core is a headless UI library for React applications, enabling developers to build highly customized, lightning-fast search interfaces powered by Algolia. It provides a set of renderless components and hooks that manage the search logic and state, abstracting away the complexities of interacting directly with the Algolia API. Unlike `react-instantsearch`, which offers pre-built DOM components, `react-instantsearch-core` focuses on providing low-level primitives suitable for both web and React Native projects, allowing maximum flexibility in UI implementation. The library is currently stable at version 7.29.0 and is actively maintained within the Algolia InstantSearch ecosystem, receiving frequent updates, typically monthly, to align with new features and improvements across the InstantSearch family of libraries. Its core differentiator lies in its headless nature, empowering developers to create unique search experiences without being constrained by opinionated UI components.

npm install react-instantsearch-core
INSTALL
IMPORT
SIG · REACT-INSTANTSEARC
R
react-instantsearch-core
http-networkingjavascriptv7.29.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

InstantSearch
import { InstantSearch } from 'react-instantsearch-core'
import InstantSearch from 'react-instantsearch-core'
This is the main context provider component for InstantSearch. It is a named export.
useInstantSearch
import { useInstantSearch } from 'react-instantsearch-core'
A React Hook to access the InstantSearch context and search state. Primarily used for creating custom widgets or accessing search data directly.
connectSearchBox
import { connectSearchBox } from 'react-instantsearch-core'
A higher-order component (HOC) connector for creating custom search box widgets. Often used when hooks are not suitable or for older patterns.
Hits
import { Hits } from 'react-instantsearch'
import { Hits } from 'react-instantsearch-core'
Pre-built UI components like `Hits`, `RefinementList`, etc., are provided by `react-instantsearch`, not `react-instantsearch-core` (which is headless).

Demonstrates setting up InstantSearch with a custom search box and hits display using `useInstantSearch` hooks.

import React, { useState, useEffect } from 'react'; import algoliasearch from 'algoliasearch'; import { InstantSearch, useInstantSearch } from 'react-instantsearch-core'; const searchClient = algoliasearch( process.env.ALGOLIA_APP_ID ?? 'YOUR_APP_ID', process.env.ALGOLIA_SEARCH_API_KEY ?? 'YOUR_SEARCH_API_KEY' ); const indexName = 'your_index_name'; function CustomSearchBox() { const { uiState, setUiState } = useInstantSearch(); const [query, setQuery] = useState(uiState.query || ''); useEffect(() => { // Synchronize local query state with InstantSearch's UI state if (uiState.query !== query) { setQuery(uiState.query || ''); } }, [uiState.query]); const handleChange = (event) => { const newQuery = event.target.value; setQuery(newQuery); setUiState(prevUiState => ({ ...prevUiState, query: newQuery })); }; return ( <input type="search" placeholder="Search..." value={query} onChange={handleChange} style={{ padding: '10px', width: '300px', marginBottom: '20px' }} /> ); } function CustomHits() { const { results } = useInstantSearch(); return ( <div> {results.hits.length > 0 ? ( <ul> {results.hits.map(hit => ( <li key={hit.objectID} style={{ marginBottom: '10px' }}> {/* Assuming your hits have a 'name' property */} <h3>{hit.name}</h3> <p>{hit.description}</p> </li> ))} </ul> ) : ( <p>No results found.</p> )} </div> ); } function App() { return ( <InstantSearch searchClient={searchClient} indexName={indexName} initialUiState={{ [indexName]: { query: '' } }} > <h1>My Custom Search</h1> <CustomSearchBox /> <CustomHits /> </InstantSearch> ); } export default App;
Debug
Known issues
gotchaThis package (`react-instantsearch-core`) provides renderless components and hooks for search logic. It does *not* include any visual UI components. Developers must build their own UI using the provided hooks and connectors. If you need pre-built DOM-rendering components, use `react-instantsearch` instead.
fix
If expecting visual components, install `react-instantsearch` instead. If building custom UI, ensure you implement rendering logic for your components.
affects: >=1.0.0
breakingReact InstantSearch v7 requires React version 16.8.0 or newer due to its reliance on React Hooks. Older React versions are not supported.
fix
Upgrade your project's `react` and `react-dom` dependencies to version `^16.8.0` or newer. The current peer dependency range is `>= 16.8.0 < 20`.
affects: >=7.0.0
breakingThe `algoliasearch` peer dependency has specific version requirements (>= 3.1 < 6). Using an incompatible version may lead to runtime errors or unexpected behavior.
fix
Ensure your installed `algoliasearch` client version is compatible with the `react-instantsearch-core` peer dependency range. Upgrade or downgrade `algoliasearch` as needed.
affects: >=6.0.0
gotchaThe `InstantSearch` component requires a valid `searchClient` prop (an instance of `algoliasearch`) and an `indexName`. Incorrect or missing values will prevent search functionality.
fix
Always provide a properly initialized `searchClient` from `algoliasearch` and the `indexName` of your Algolia index to the `InstantSearch` component. Ensure your API keys are correct and have appropriate permissions.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot resolve module 'algoliasearch'
The `algoliasearch` package is a peer dependency but is not installed in the project.
fix
Install `algoliasearch`: `npm install algoliasearch` or `yarn add algoliasearch`.
Error: Invalid `searchClient`. It looks like `algoliasearch` was not passed to the `InstantSearch` component.
The `searchClient` prop of the `InstantSearch` component is either missing or an invalid Algolia search client instance.
fix
Ensure you are passing a valid `algoliasearch` client instance, like `algoliasearch('APP_ID', 'API_KEY')`, to the `searchClient` prop of the `InstantSearch` component.
Error: Hooks can only be called inside of the body of a function component.
React Hooks like `useInstantSearch` are being called outside of a functional React component or a custom Hook.
fix
Ensure all calls to `useInstantSearch` (or other React Hooks) are made within the top level of a functional component or a custom Hook.
Upgrade
Version history
7.29.0latest on npm
Audit
Dependencies
algoliasearchrequiredRequired for communicating with Algolia APIs and managing search state.
reactrequiredCore dependency for building React components.
Agent activity
22 hits · last 30 days
node
18
OpenAI (training)
1
Resources
react-instantsearch-core — npm install react-instantsearch-core · libregistry