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.

connectStateResults freezes with dynamic hitComponent

See original GitHub issue

Do you want to request a feature or report a bug? Bug

Bug: What is the current behavior? Application freezes; most likely hit component is rendered in a loop

What is the version you are using? Always use the latest one before opening a bug issue. 4.1.3

Here is the example I’m testing on https://codesandbox.io/s/kxlq9608v3 I am using connectStateResults to wrap my Hits to conditionally render them based on search query. I want to pass props to hitComponent, as mentioned here algolia/react-instantsearch#2018 . Following the solution in that issue, I created a dynamic hitComponent, ie instead of

const Content = connectStateResults(
  ({ searchState }) =>
    <Hits hitComponent={HitComponent}/>
);

I tried

const Content = connectStateResults(
  ({ searchState }) =>
    <Hits hitComponent={({hit}) => (<HitComponent hit={hit}/>)}/>
);

This freezes the application. If I remove the connectStateResults wrapper, it works as expected. Also, this seems to be a problem with connectStateResults only; wrapping in connectHits works. Any help is appreciated!


<small>originally https://github.com/algolia/instantsearch.js/issues/2586</small>

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:4
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
wzupcommented, Aug 30, 2018

Same here. connectStateResults is infinite loop. Always returns searching=true case.

const Content = connectStateResults(
  ({ searchState, searching, onSearchStateChange, getSelected }) => {
    if(searching) {
      return <Text>
        SEACHING...
      </Text>
    } else {
      return (
        <InfiniteHits onSearchStateChange={ onSearchStateChange }
                      searchState={ searchState }
                      getSelected={ getSelected }/>
      )
    }
  }
);

              <InstantSearch
                appId="..."
                apiKey="..."
                indexName="..."
                onSearchStateChange={ this.props.onSearchStateChange }
                searchState={ this.props.searchState }
                refresh={ true }
                // resultsState={ { query: '...' } }
              >
                { /*<RefinementList attribute="..." headerText={ '...' } />*/ }
                <TouchableOpacity
                  onPress={ () => {
                    this.props.setModalVisible(false);
                  } }
                >
                  <Text style={ { marginTop: 20, height: 50, alignSelf: 'center', fontSize: 14 } }>
                    Close
                  </Text>
                </TouchableOpacity>
                <SearchBox />
                <Content
                  onSearchStateChange={ this.props.onSearchStateChange }
                  searchState={ this.props.searchState }
                  getSelected={ this.props.getSelected }
                />
              </InstantSearch>
2reactions
m-vdbcommented, Apr 18, 2018

Having the same issue with react-instantsearch@v5.0.3.

Read more comments on GitHub >

github_iconTop Results From Across the Web

connectStateResults freezes with dynamic hitComponent
I am using connectStateResults to wrap my Hits to conditionally render them based on search query. ... const Content = connectStateResults( ({ ...
Read more >
StateResults | React InstantSearch
The StateResults widget provides a way to access the searchState and the searchResults of InstantSearch. For instance, this widget allows you to create...
Read more >
react-instantsearch-dom @ 5.4.0 .. 5.6.0 - Package Diff
throw new Error('Dynamic requires are not currently supported by ... react-instantsearch-core/dist/es/connectors/connectStateResults.js","../../.
Read more >
Interface with Algolia through Craft CMS | REST library - kandi
Implement algolia with how-to, Q&A, fixes, code snippets. kandi ratings - Low support, No Bugs, No Vulnerabilities. Permissive License, Build available.
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