react-instantsearch icon indicating copy to clipboard operation
react-instantsearch copied to clipboard

How to Refresh Hits after adding a new Object?

Open tobiastheil opened this issue 9 years ago • 5 comments

Hey,

I am displaying results in my Single Page Application with <Hits />.

After adding a new Page (including Indexing) I would like to trigger a refresh of the Hits.

client.clearCache() does not work.

Any hints?

tobiastheil avatar May 18 '17 11:05 tobiastheil

Hello @tobiastheil,

I believe that unmounting your current InstantSearch instance and mounting a new one can do the trick.

mthuret avatar May 18 '17 15:05 mthuret

Hey,

I have tried that. I have also tried adding a delay. Sometimes it works, sometimes is doesn't. The UX of it isn't that great.

Can I somehow trigger a search and then reset it?

tobiastheil avatar May 19 '17 07:05 tobiastheil

My solution is that I hide the search when the query is empty. Instead of the component I present a List of all the items based on an internal Array that I can "control"

tobiastheil avatar May 19 '17 08:05 tobiastheil

Can you share some code to help me see how you solve this?

mthuret avatar May 19 '17 08:05 mthuret

<InstantSearch ...>
              <SearchBoxWrapper>
                <SearchBox
                  autofocus
                  placeholder='Type to search'
                  onFocus={this.onFocus}
                  onBlur={this.onBlur}
                  focusShortcuts={['s', '/', 191]}
                />
              </SearchBoxWrapper>

              {searchState.query !== '' ?
                <Hits hitComponent={Note} />
              :
                <div>
                  {notesWithoutFolder.map(note =>
                    <Note key={note.id} hit={note} />
                  )}
                </div>
              }

            </InstantSearch>

tobiastheil avatar May 19 '17 09:05 tobiastheil