question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using Autocomplete with react-instantsearch-dom HOCs

See original GitHub issue

I’m currently trying to implement a search field using react-instantsearch-dom and chakra-autocomplete. I seem to be hitting a wall when rendering the AutoCompleteList. I believe the issue is that the reference or context of AutoComplete is getting lost but I’m not sure how to solve it.

The search box part looks like this

  <AutoComplete rollNavigation id="autoTop" itemRef="auto">
    <AutoCompleteInput
        value={currentRefinement}
        variant="filled"
        placeholder="Search..."
        minW="500px"
        autoFocus
        onChange={(e) => handleQuery(e)}
        id="auto-input"
      />
      <SearchResults />
    </AutoComplete>

With the SearchResults component looking like this and then being wrapped in the instantsearch HOC with connectHits()

const HitBase = ({ hits, handleClick }: HitProps) => {
  console.log(hits)

  return (
    <AutoCompleteList >
      {hits.map((hit) => (
        <AutoCompleteItem key={hit.title} value={hit.title}>
          <Poster id={hit.id} slug={hit.poster_path} title={hit.title} />
          <Text>{hit.title}</Text>
        </AutoCompleteItem>
      ))}
    </AutoCompleteList>
  )
}
const SearchResults = connectHits(HitBase)

Is there a way to maintain the reference between the two components? My assumption is that the hits HOC is what actually breaks it but I am not sure how to get around it.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
anubra266commented, Sep 23, 2021

Hi @SteveWallace found a way around this, so it’s fixed in v4.6.0.

1reaction
SteveWallacecommented, Sep 13, 2021

@anubra266 No problem! I get why you built it that way and it makes sense. I suspected that would end up the case. I appreciate you having a look.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Integrate Autocomplete with React InstantSearch - Algolia
Learn how to use Autocomplete with React InstantSearch. ... from 'react-instantsearch-dom'; import qs from 'qs'; const VirtualSearchBox ...
Read more >
Add react hooks · Issue #2870 · algolia/react-instantsearch
Problem: Connector HOCs add boilerplate and can be unwieldy. When you have an existing component already the modification to make it connected is...
Read more >
react-instantsearch-dom | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
How to use the react-instantsearch-dom ... - Snyk
log('searchState', searchState); }} > <AutoComplete isHome={isHome} /> <Configure hitsPerPage={5} distinct={true} /> <Index indexName="0x_tools_test" /> <Index ...
Read more >
10 Best React Autocomplete Libraries in 2023 - Openbase
A comparison of the 10 Best React Autocomplete Libraries in 2023: ... React hook for Google Maps Places Autocomplete. ... react-instantsearch-dom ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found