algolia / react-instantsearch

⚑️ Lightning-fast search for React and React Native applications, by Algolia.
https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/react/
MIT License
1.97k stars 386 forks source link

Hits array is not being updated #3644

Closed vpaul18 closed 1 year ago

vpaul18 commented 1 year ago

πŸ› Bug description

I have been struggling for hours now as to why the hits array passed as props is empty.

πŸ” Bug reproduction

Here is a full reproduction of the problem I'm facing:

https://codesandbox.io/s/cocky-snowflake-gni9uf?file=/src/App.js

πŸ’­ Expected behavior

I expect the results of the search (each hit) to show up after a keystroke. I am also using the same datasets provided by you, so I'm confident that the data exists.

Environment

Additional context

That would be it! Thanks!

VishnuuVijayan commented 1 year ago

I have the same issue, if you give an api call through postman it actually works

Haroenv commented 1 year ago

Does this happen with other versions as well?

vpaul18 commented 1 year ago

@Haroenv This sandbox seems to work : https://codesandbox.io/embed/kvn0lpp83?codemirror=1 , but If I match their dependencies and imports , I get export errors from the packages.

@VishnuuVijayan Yes, it does seem to work… when the page rerenders (for example if I change a CSS class) - I can see the hits …

sarahdayan commented 1 year ago

Hey @vpaul18, the issue comes from React strict mode usage. It disappears in React InstantSearch 6.37.0, where we added React 18 strict mode support.

I updated to 6.38.0 and did a couple changes on your sandbox and it seems to work just fine now.

Updated sandbox ➑️

Note that we're passing currentRefinement as the input's value, making it controlled. The updated value comes from React InstantSearch, which updates it when using refine.

If you want to stay on 6.34.0, you need to drop strict mode (see here).