Search code examples
algoliainstantsearch

Algolia InstantSearch Hook - search for an array of objectIDs


we're using Algolia's InstantSearch React hook

I figured I could do something like the following

<InstantSearch 
    indexName={indexName} 
    searchClient={algoliaClient}
    searchState={{
       query: [
          "objectID:80066451052",
           "objectID:50090402178"]
    }}>
      <Configure clickAnalytics />
      {children}
 </InstantSearch>

But it turns out that the InstantSearch hook does not support searchState the way the older InstantSearch component does.

So can anyone help me turn the query above into one that will work with the InstantSearch hook?


Solution

  • I don't know which version you're using and how your index is configured.

    However, the query can be passed directly to the Configure component like any other search parameter you can found here

    https://www.algolia.com/doc/api-reference/search-api-parameters/

    So you can write this

    <InstantSearch 
    indexName={indexName} 
    searchClient={algoliaClient}
    >
      <Configure query={myQuery} clickAnalytics/>
      {children}
    </InstantSearch>